Screenshot of Finder window.

Hi Guys,

Looking to take a screenshot of the active finder window. There are some complicated shell scripts on MacScripter which I can’t get to work. Here’s my AS using GUI scripting.


tell application "System Events"
	tell process "Finder"
		set frontmost to true -- Thanks again Stefan K
		keystroke "t" using {command down, option down} -- Hides window sidebar. 
		keystroke "4" using {shift down, option down} -- Screenshot of window only.
		keystroke space
		
	end tell
end tell

The last line “keystroke space” doesn’t work. Is there a listing somewhere of ASCII keycodes that I can reference? Also tried “spacebar” without success.

The next thing will be to script the mouse click (and possible the position of the pointer). What is the syntax for this?

Hi Matt

heres some stuff I use on and of

do shell script "DATE=`date '+%Y%d%m-%H%M%S'`;
FILE=~/Pictures/screenshot-${DATE}.png;
screencapture -i -W -x $FILE;
if [ -e $FILE ]; then
open /Applications/Preview.app $FILE;
fi"
set _folder to (path to desktop) as string
set _filename to text returned of (display dialog "Enter file title." default answer "") & ".png"
try
	--- capture whole screen ---
	do shell script "/usr/sbin/screencapture -iW " & ((quoted form of POSIX path of _folder & _filename) as string)
	--- get selections of screen ---
	--do shell script "/usr/sbin/screencapture -is " & ((quoted form of POSIX path of _folder & _filename) as string)
end try
set dFolder to "~/Desktop/screencapture/"
do shell script ("mkdir -p " & dFolder)
repeat 2 times -- Repeat 2 times.
	set tTime to do shell script "date +%H%M%S"
	do shell script ("screencapture " & dFolder & tTime & ".png") -- Capture screen.
	--delay 30 -- Wait for 30 seconds.
end repeat

hope these help out

Why not the simple:

keystroke “$” using {command down}
delay 0.08
keystroke " "

On a French keyboard. it must be.

keystroke “4” using {command down, shift down}
delay 0.08
keystroke " "

Yvan KOENIG (from FRANCE jeudi 25 juin 2009 13:19:28)

Hi Tom,

Thanks for the input. I’ve got the script to a functional level. As Yvan noted, my syntax of :
“keystroke “4” using {command down, shift down} – Screenshot of window only.”
Just doesn’t work - thanks for the heads up on the “$” + command down.

There may be a way to achieve this minus the addition but I wound up installing “Extra Suites” to help with the mouse control and the mouse click.

Here’s the script :

tell application "System Events"
	tell process "Finder"
		
		set frontmost to true -- Thanks again Stefan K
		delay 0.08 -- increase as needed
		keystroke "h" using {command down, option down}
		delay 1
		keystroke "t" using {command down, option down} -- Hides window sidebar.
		delay 2
		
		tell application "Extra Suites"
			ES move mouse {640, 512}
		end tell
		
		delay 1
		-- keystroke "4" using {command down, shift down} -- Screenshot of window only.
		keystroke (ASCII character 36) using {command down} -- Thanks Tom X
		delay 1
		keystroke (ASCII character 32) -- Space bar ???
		delay 2
		
		tell application "Extra Suites"
			ES click mouse
		end tell
		
		delay 1
		
		keystroke "t" using {command down, option down} -- Hides window sidebar.
		
	end tell
	
end tell

The mouse position is based on the window to be captured being central on the display.

Not sure of your reference to tweaking a “Stefan K” script, my reference to him was just the line of code that got me out of bind.

Next I’ll work on automatically opening capture and printing to a laser printer, which is the goal for my script.

Thanks again.