The 
legend of ROGER CLARK

Snippets/ScreenieAppleScript

Automatic screenshot capture and upload in AppleScript

After buying a Macbook, the biggest thing I was missing after making the switch was Screenie. It's pretty simple -- it takes screenshots and uploads them to your website, copying the URL of the image to the clipboard after it's finished.

So I spent a bit screwing around with AppleScript and cooked up a crudely-fashioned replacement. This script asks you for a description of the screenshot, calls the screencapture command that lets you select an individual window, saves it to a local file, uploads that file to your FTP site, and copies the resulting HTTP URL to your clipboard.

What I learned from this is that AppleScript is, while powerful, pretty fucking obtuse. You know there's something wrong when your programming language has articles. The line set theAnswer to text returned of the result is completely incomprehensible.

Anyway, change my info in this script to match your information and it should work. Everything is hardcoded, but you can easily change stuff. Look up the parameters for screengrab and you'll probably find some crap to do. Also, you've gotta have curl installed, but AFAIK it comes with the OS. Run the script with a hotkey in QuickSilver or something.

activate

display dialog "Enter a description:" default answer ""
set theAnswer to text returned of the result

set {year:y, month:m, day:d} to (current date)
set theDate to (y * 10000 + m * 100 + d) as string
set theFilename to theDate & "-" & theAnswer & ".png"
set theURL to "http://drano.org/screenshots/" & theFilename

set theScript to "FILE=~/screenshots/" & theFilename & ";screencapture -i -W -x $FILE; if [ -e $FILE ];
    then curl -T $FILE -u drano:mypassword ftp://ript.net/www.drano.org/screenshots/" & theFilename & "; fi"
do shell script theScript

tell application "Finder" to set the clipboard to theURL as text

Stuff you'll need to change:

  • ~/screenshots/ is the local directory where the screenshot file ends up.
  • http://drano.org/screenshots/ is the base URL for the image
  • drano:mypassword is your username:password
  • ftp://drano.org/httpdocs/screenshots/ is the FTP URL to the location that corresponds to your base URL

Have fun.

Edit this page. Last modified on March 20, 2008, at 04:22 AM EST.
Copyright © 2007 Roger Clark.