Automating+Screenshots

Over in the Macworld forums, a reader [|posted this question]: 'basically, i would like press a key and automatically send to the default printer a screen shot of the "active window"'.

As a Windows tech support person, the poster had a Windows application that did just this, residing in the system tray. When someone had an issue, he asked them to print their screen and then bring him the printout. [|Snapz Pro] can do this, but I thought that maybe I could use Automator to come up with a passable solution as well. After some experimentation, I came up with a couple of alternatives that basically get the job done, nearly as easily as does the Windows program.


 * Option #1: Printing screenshots**

My first solution puts the machine in window-capture mode, waits for the user to click the mouse button, then sends the capture to the printer. I couldn't see any way to automatically capture the "active" window, so some user interaction is required. In order to use this solution, you'll need to have a directory for the captured images ( in my example). Also, in order to create the workflow, you'll need to have an existing file in that folder (named in my example). One way to create the file is via Terminal; launch it and type to create the file (put the proper path in to your captured images folder, of course).

In Automator, create a new workflow: That's it for the workflow. Save it as an Application, and then put it in the user's Dock. When they have a problem, tell them to click the icon in their dock, move the mouse until the troublesome window is highlighted, and click the mouse button. The output will then appear on the printer.
 * 1) Automator Library » Run Shell Script: Leave Shell as  and Pass Input as, and then enter this code: . What this command does is start the command line  tool, forcing it into interactive window-only selection mode (the camera icon). Replace  with the actual path to your  folder, of course. Alternatively, you could just copy any file in there and rename it to ; it's only needed once to set up the workflow, then it will be overwritten.
 * 2) Finder Library » Get Specified Finder Items: Click the plus sign, and navigate to the  file you created earlier.
 * 3) Finder Library » Print Finder Items: Set the printer to be used in the pop-up menu.
 * 4) Finder Library » Move to Trash.


 * Option #2: Save the trees!**

Since it seemed something of a waste of paper to print out every screenshot, I thought a better alternative might be to use the technology to send a trouble ticket via email, with the screenshot attached. You'll need the same prerequisites as for the first workflow -- a folder to hold the images, and a pre-existing file in that folder. Then create this Automator workflow: Again, that's all there is to it. Save this as an application, put it in the dock, and your users will now email you screenshots of their troublesome apps.
 * 1) Same as step #1 above.
 * 2) Same as step #2 above.
 * 3) Mail Library » New Mail Message. The screen capture will automatically be inserted into the new message with this action (very handy!). Just fill in the To, Subject, and Message fields as you desire -- by specifying the Subject, you can then use a Mail filter to group all the tech support screenshots into one Mail folder, for example.
 * 4) Automator Library » Run Shell Script: Again leave  and, and enter this code: . We have to use a shell script to remove the file here, unlike in the first workflow, because the Mail action we added won't pass through the Finder selection to the final step.

Obviously these are just starter workflows; it's possible to do much more using the power of the utility and Automator. You could, for instance, remove the delete steps, add some rename actions, and create an archive of screenshots for each user. To make it easier to run the scripts, you could use Butler, QuicKeys, or another macro utility to assign a hot key to open the application (bind it to an F-key for ease of use).

While not a perfect replacement for the Windows solution (as it does require a little bit of user interaction), I think these solutions get the job done with a very low chance for user error.