How to display the "Grab" "Save..." dialog box

This is a simplified section of a larger script which at one stage is using “Grab” to take a snapshot of a window the user will select when prompted. I use “Grab” instead of the shell “/usr/sbin/screencapture” because the direct output is a tiff file of the trimmed window (without shade).


tell application "Grab"
	activate
end tell
tell application "System Events"
	keystroke "W" using command down
end tell
delay 5 -- 5 seconds to click on the desired window.
tell application "Grab"
	activate
end tell

-- The next script step isn't working.
tell application "System Events"
	keystroke "S" using command down
end tell

Once the snapshot is taken and promoted to the top, I want the script to pop up the “Grab” “Save.” dialog box. The sample script does prompt the user to select a window, takes and promotes the snapshot, but then it fails to pop up the “Save.” dialog box. Why? How can I fix the script? Can anybody please help?

Note that pressing command-s manually does display the “Save.” dialog box.

Hi,
usual the command for saving a file choosing a name is:

choose file name with prompt "Save." default location alias (path to desktop folder) default name "Snapshot.txt"

but your intent is useless, because ‘Grab’ doesn’t support applescript. At least not on Snow Leopard, where i am. And UI scripting does nothing more or less than to simulate a certain button press.
you’ve to study the entire man page of screencapture to understand its commands:

set pt_desk to POSIX path of (path to desktop folder as text)
do shell script "screencapture -t jpg '" & pt_desk & "myscreen.jpg" & "'"

Hope this helps

Hi Joy, many thanks. You are right, Grab is not scriptable in Lion either. After reading the manual about “screencapture” as you kindly suggested, I found out how to do it to capture windows as well. Any graphics type (jpg, png, tiff, …) can also be specified. It can capture any window you select with the camera cursor:


set pt_desk to POSIX path of (path to desktop folder as text)
do shell script "screencapture -iw -t tiff '" & pt_desk & "mywindow.tiff" & "'"

or a little bit simpler:


do shell script "screencapture -iw ~/desktop/mywindow.tiff"

Obviously, to make the script more useful a dialog box can be added to specify the output file name to take the window title as the default name, or user input.