Looking for the script to take a screenshot, Grab is apparantely unscriptable.
To simply take a picture, you can use something like this…
do shell script "screencapture " & quoted form of "/Users/jed/Desktop/Whatever.pdf"
To get more complex and make sure you’re not overwriting an existing file, this script will mimic what the finder does (shift-command-3)…
set outputLocation to (path to desktop) --> Any colon-delimited location to save the captures
set fileName to "Picture " --> The filename prefix
--> Inspect existing files in directory for potential naming conflicts
tell application "Finder" to set currFiles to (displayed name of files in outputLocation)
set highInt to 0
repeat with tmpFile in currFiles
try --> See if the file has a file number
if (text 1 through 8 of (tmpFile as string)) is equal to "Picture " then
try
set tempInt to (text 9 through -1 of (tmpFile as string)) as number
on error
set tempInt to 0
end try
end if
if tempInt > highInt then set highInt to tempInt --> Records highest file # found
end try
end repeat
set highInt to (highInt + 1) --> Create the incremented file number
--> Shell script to do screen capture
set newFilePosixPath to (outputLocation & fileName & highInt & ".pdf") as string
set newFilePath to POSIX path of newFilePosixPath
do shell script "screencapture " & quoted form of newFilePath
--> Hide the extension
tell application "Finder" to set extension hidden of alias newFilePosixPath to true
j