Mar 20, '07 07:30:04AM • Contributed by: robg
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 (screencaps in my example). Also, in order to create the workflow, you'll need to have an existing file in that folder (named screencap.png in my example). One way to create the file is via Terminal; launch it and type touch /path/to/screencaps/screencap.png to create the file (put the proper path in to your captured images folder, of course).
In Automator, create a new workflow:
- Automator Library » Run Shell Script: Leave Shell as /bin/bash and Pass Input as to stdin, and then enter this code: screencapture -wiW /full/path/to/screencaps/screencap.png. What this command does is start the command line screencapture tool, forcing it into interactive window-only selection mode (the camera icon). Replace /full/path/to with the actual path to your screencaps folder, of course. Alternatively, you could just copy any file in there and rename it to screencap.png; it's only needed once to set up the workflow, then it will be overwritten.
- Finder Library » Get Specified Finder Items: Click the plus sign, and navigate to the screencap.png file you created earlier.
- Finder Library » Print Finder Items: Set the printer to be used in the pop-up menu.
- 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 screencap.png file in that folder. Then create this Automator workflow:
- Same as step #1 above.
- Same as step #2 above.
- 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.
- Automator Library » Run Shell Script: Again leave /bin/bash and to stdin, and enter this code: rm /full/path/to/screencaps/screencap.png. 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 screencapture 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.
