I was trying to do a screen capture of a safari window
I found this script example after searching the forum
tell application "System Events" to tell process "Safari"
activate
--bring the page to the front
set frontmost to true
--set keystrokes for sceenshot of window
keystroke "4" using {command down, shift down}
delay 1
keystroke space
end tell
tell application "Extra Suites"
--use the Extra Suites to click the mouse in the window
ES move mouse {600, 300}
ES click mouse
end tell
However this doesn’t seem to work. Safari is brought forward and the mouse is moved but the screen capture never happens. There are no errors from running the script, it just doesn’t achieve the desired result
There is a box at the bottom of any Universal Access System Preferences pane called: “Enable access for assistive devices”. That must be checked for GUI scripting to work.
In the Keyboard & Mouse pane of System Preferences under the Keyboard Shortcuts tab, Screen shots must be enabled by checking the appropriate boxes.
Done and done.
The process works if I do it manually (press cmd/shift + 4 then space and click the window) the extras suites is clicking in the window but the screen shot is not.
Well, I agree with you; it doesn’t work for me either. Apparently the screen capture facility isn’t receiving the keystrokes. Further, the shell “screencapture” facility doesn’t seem to work without interaction either.
I made this script that capture the screen area (clip) and save it to a chest under the website with time stamp. It puts the URL in the spotlight comments for reference
property TheURL : "http://www.macscripter.net/"
property SuffixOptions : {".com", ".net", ".org", ".info", ".us", ".biz", ".tv", ".mobi", ".cc", ".ws", ".bz", ".tc", ".vg", ".ms", ".gs", ".name", ".co.uk", ".de", ".be", ".eu", ".at", ".com.mx", "org.uk", ".me.uk", ".co.nz", ".net.nz", ".org.nz", ".cn", ".tw"}
tell application "Safari"
activate
if document 1 exists then
set TheURL to URL of document 1
else
make new document
delay 5
end if
end tell
set TheHost to FindDomainName(TheURL)
set TimeStamp to do shell script "date -n +%Y-%m-%d-%H-%M-%S"
set thepath to ((path to desktop) as string) & "chest:clips:" & TheHost & ":"
set TheName to TheHost & "-" & TimeStamp & ".png"
do shell script "mkdir -p " & (POSIX path of thepath)
set theFile to thepath & TheName
do shell script "screencapture -mix " & (POSIX path of theFile)
tell application "Finder"
set comment of file theFile to TheURL
end tell
on FindDomainName(TheURL)
set TheSuffix to ""
repeat with CurrentSuffix in SuffixOptions
if TheURL contains (CurrentSuffix & "/") then
set TheSuffix to CurrentSuffix
exit repeat
end if
end repeat
if TheSuffix = "" then
return "Misc"
else
set SuffixOffset to offset of (CurrentSuffix & "/") in TheURL
set JustDomain to (characters 1 thru (SuffixOffset - 1) of TheURL) as string
set PointOffSet to 0
repeat with NegOffSet from (length of JustDomain) to 1 by -1
if character NegOffSet of JustDomain is "." or character NegOffSet of JustDomain is "/" then
set PointOffSet to NegOffSet
exit repeat
end if
end repeat
try
set JustDomain to (characters (PointOffSet + 1) thru (length of JustDomain) of JustDomain as string) & CurrentSuffix
on error
set JustDomain to "Misc"
end try
return JustDomain
end if
end FindDomainName
I seem to have found a fix, or better put a work around.
I used Extra Suites to type the first part (4+CMD+SHIFT+CTL). The odd part was that having ES do the “space” generated an error, so I did that with System Events. Still no explanation as to why.
tell application "Extra Suites"
ES type key "4" with command, shift and control
delay 1
end tell
tell application "System Events"
keystroke space
end tell
tell application "Extra Suites"
--use the Extra Suites to click the mous in the window
ES move mouse {400, 24}
ES click mouse
end tell
don’t work for me either. Its act as if it work but no file is created.
grab or set the window position
Screenshot the whole screen in UNIX
Crop in image editing using saved window position
I did this method with 300+ websites, built a database and layed up in quark a document for print.
Or use UNIX screencapture and put up with the user interaction. A click takes a second. At less you can name the file and put it where you like.
3rd party like Snapz Pro or CaptureMe have applescript but very basic. None could select area or a window by Applescript. Maybe something out there, CaptureMe promise an update to Applescript support.
Below a script downloaded from this forum (not entirely certain)
run this and click your mouse
it captures the last active window and saves to your desktop
set target_folder to (path to desktop) as string
set file_name to text returned of (display dialog "Enter file title." default answer "") & ".png"
try
do shell script "/usr/sbin/screencapture -iW " & ((quoted form of POSIX path of target_folder & file_name) as string)
on error theErr
display dialog theErr
end try
This sequence appears to automate the process of taking window shots of Safari with the help of Extra Suites.
It works though I think it is slower than just clicking the mouse ! Unless you want a timer.
I have no idea why this configuration appears to work when others don’t.
Create a folder named My Safari Screenshots on the desktop.
Create two applications (see below) one of which is a stay open application.
a) Application 1 (saved as a stay open Application - name (say) MySafari ES)
on idle
tell application "Finder"
if (get name of every process) does not contain "MySafariShot" then
tell me to quit
end if
end tell
tell application "Extra Suites"
activate
ES move mouse {900, 400}-------adjust to suit screen size
ES click mouse
ES click mouse
end tell
return 1
end idle
b) Application 2 (saved as an Application - name (say) MySafariShot)
property N : 0
set N to N + 1
activate application "MySafari ES"
tell application "System Events"
copy every process to theList
repeat with theProcess in theList
try
if frontmost of theProcess is false then
set visible of theProcess to false
end if
end try
end repeat
end tell
tell application "Safari"
activate
set zoomed of window 1 to true
end tell
set myfolder to alias ((path to desktop from user domain) & "My Safari Screenshots" & ":" as string)
tell application "Finder"
set numberOfFiles to count of (files in folder myfolder)
end tell
set picPath to ((POSIX path of (myfolder)) & "Safari-Screenshots " & N & ".png") as string --- to your desired location and change the ".png" file type to whatever you might want (.jpg, .tiff, etc.)
do shell script "/usr/sbin/screencapture -iW " & quoted form of picPath
tell application "Finder"
set Newnumber to count of (files in folder myfolder)
end tell
if Newnumber ≠numberOfFiles then
tell me to quit
end if
Assuming you have a Safari window open, activate by doubleclicking application “MySafariShot” .
The shot of the Safari window will be taken and stored in the folder “My Safari Screenshots” on the desktop.
Both applications will quit.
Consider, however, if you are there to click the application, it just as easy to click the mouse !
About::
Paparazzi! is a small utility for Mac OS X that makes screenshots of webpages.
It’s written in Objective-C using the Cocoa API and the WebKit framework.