Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'A script to create uniquely-named screenshots' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to create uniquely-named screenshots
Authored by: hypnopixel on Oct 07, '06 01:14:24PM

some refinements... now, less error-prone!

do shell script operates at working directory / so giving the screencapture command just a filename without a path saves it to boot root /filename which is considered sub-optimal.

eliminate the mv and ambiguity by specifying the full pathname of the image file to screencapture.






-- msb - manage screenshots better; save named screenshots somewhere other than the desktop

-- prompt for screenshot name; cancel stops the script from continuing

display dialog "Name your screenshot?" default answer "" buttons {"OK", "Cancel"} default button 1

set picName to text returned of the result

-- this just adds a . delimeter after the picName, if supplied

if (picName is not "") then set picName to picName & "."

do shell script "

# timestamp to make unique filename; format is like Sat.07.Oct.06_12.44.15

timestamp=$(/bin/date \"+%a.%d.%b.%y_%H.%M.%S\")

# screencapture -t pic type and filename extension; default is png

fileExtension=png

# save screenshots here

targetDir=\"$HOME/Pictures/screenshots\"

# if targetDir is missing, make it

if [ ! -d $targetDir ]; then /bin/mkdir $targetDir; fi

# craft the full /path/to/image/filename

filename=\"$targetDir/" & picName & "screenshot.$timestamp.$fileExtension\"

# emulate command-shift-4 screenshot function in interactive mode; see man screencapture

/usr/sbin/screencapture -i -t$fileExtension \"$filename\"

# open the image with preview.app; check for file in case the user cancels the screencapture with escape

if [ -f $filename ]; then /usr/bin/open -a preview \"$filename\"; fi
"

-- end




[ Reply to This | # ]
A script to create uniquely-named screenshots
Authored by: hypnopixel on Oct 07, '06 01:26:18PM

ack! regrets, variables $targetDir and $filename in the above if statements should be quoted \"foo\" like the others to be bullet proof.



[ Reply to This | # ]