Over the past couple of days I’ve been putting together an automated screen grab script.
The first version of the script works fine, I can drag and drop several files onto the script and the screen grabs are placed in a folder called ‘screen_grabs’ on my desktop.
I was wanting to take the script one step further so the screen grabs are saved in the same folder as the individual files dropped onto it and therefore save me time having to do the file management.
Here’s the script so far:-
on open (someItems)
repeat with theitem in someItems
tell application "Finder" to set thePath to (container of (theitem)) as string
set thePathPosix to POSIX path of thePath
set {atid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
set fileName to the last text item of (theitem as text)
set AppleScript's text item delimiters to atid
(*
TELL APPLICATION - OPEN theItem
*)
set format_ to "png"
do shell script "/usr/sbin/screencapture -mt" & format_ & thePathPosix & fileName & "." & format_
(*
TELL APPLICATION - CLOSE theItem
*)
end repeat
end open
As mentioned, version 1 of the script works fine however version 2 doesn’t. I’m pretty sure it’s to with the way I’m combining the ‘thePathPosix’ with the rest of this:-
there are some space characters missing in the shell script line to separate the parameters
Try this
on open someItems
repeat with theitem in someItems
tell application "Finder" to set {fileName, thePath} to {name of theitem, container of theitem as text}
set thePathPosix to POSIX path of thePath
(*
TELL APPLICATION - OPEN theItem
*)
set format_ to "png"
do shell script "/usr/sbin/screencapture -m -t " & format_ & space & quoted form of (thePathPosix & fileName & "." & format_)
(*
TELL APPLICATION - CLOSE theItem
*)
end repeat
end open
Thanks for your help my query and for tidying up my code. Once again it’s been an education, it’s great being able to compare your tweaks with my original.
I’ve tried implementing your changes however the script still appears to be failing when it comes to the saving of the screen grab. I’ve tried the obvious like filename too long and getting rid of odd characters but still no joy?
The files are opening up and closing ok.
That’s the proper syntax of my script
Anyway there must be a space character after the t flag.
A flag like the t flag with a following parameter must be specified separately
the shell line without variables must look like
do shell script "/usr/sbin/screencapture -m -t png '/path/to/image.png'"