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

10.4: Automate the capture and printing of screenshots Apps
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:
  1. 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.
  2. Finder Library » Get Specified Finder Items: Click the plus sign, and navigate to the screencap.png 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.
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.

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:
  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 /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.
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.

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.
    •    
  • Currently 1.75 / 5
  You rated: 1 / 5 (4 votes cast)
 
[11,211 views]  

10.4: Automate the capture and printing of screenshots | 8 comments | Create New Account
Click here to return to the '10.4: Automate the capture and printing of screenshots' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Automate the capture and printing of screenshots
Authored by: ton007 on Mar 20, '07 09:59:57AM

An even easier way would be:

In Automator, create a new workflow:

1. System Library > Take Screenshot. Select Type > Full Screen. (Or alternatively Type > Interactive > Choose Window). Select Save To > New. Browse to and select Mail.

2. 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.

3. Mail Library > Send Outgoing Messages

That's it.



[ Reply to This | # ]
10.4: Automate the capture and printing of screenshots
Authored by: robg on Mar 20, '07 10:01:16AM

Hehe. I didn't even think to search or look at the System section -- thanks :)

-rob.



[ Reply to This | # ]
Error
Authored by: MtnBiker on Mar 20, '07 11:30:26AM

Correction Step 1:
Was: Select Save To > New
Should be: Select Save To > Other

YMMV

---
Hermosa Beach, CA USA



[ Reply to This | # ]
Error
Authored by: ton007 on Mar 20, '07 12:39:27PM

You're right. New lets you save to a file, Other lets you save to an app. Thanks for the correction.



[ Reply to This | # ]
10.4: Automate the capture and printing of screenshots
Authored by: sonic68 on Mar 20, '07 12:01:28PM

When I use the Print Finder Items it keep opening the printer setup utility every time I run the app. I have the printer set up through bonjour should I set it up through ip printing?

Jeff W.



[ Reply to This | # ]
10.4: Automate the capture and printing of screenshots
Authored by: michaelj on Mar 20, '07 02:20:47PM

Very nice. ton007's workflow is less geeky, but works quite well and eliminates the need to click again. Of course, if the user has buried the error message or problematic active window, then you don't get the desired result...



[ Reply to This | # ]
10.4: Automate the capture and printing of screenshots
Authored by: mark hunte on Mar 20, '07 05:20:55PM
Just to see if I could do what I think the the Windows app did.
(Screengrab and Auto print) sorry trees

First I reset the Path my screen grabs saved too.

To change the path use


defaults write com.apple.screencapture location /Full/PathToyour/GrabFolder/
(The folder you choose has to exist)

You then Have to logout and back in for it to take effect.
Note Also that although the .plist file may not exist before you do this.
It will be created.

In Automator Create a workflow.
From the 'Preview' Actions' use Print Images.
I set the Options I needed, Scale to fit, Auto rotate, Default Printer.
And saved it as an Automator app named 'Print_Screen'

Save and attach the following folder action to the folder GrabFolder.


on adding folder items to this_folder after receiving added_items
	tell application "Finder"
		repeat with i from 1 to number of items of added_items
			set input to item i of added_items as alias
			tell application "Print_Screen"
				set input to input as string
				open input
				delay 2
			end tell
		end repeat
	end tell
end adding folder items to
Now all I have to do is

Command + shift + 4, then hit the Space bar. I get the Window interaction Screengrab.
Choose my window. by selecting it.

The screen grab goes straight to the GrabFolder, and the folder action in effect send it straight to the printer.

---
mh

[ Reply to This | # ]

10.4: Automate the capture and printing of screenshots
Authored by: Doc Drang on Mar 20, '07 08:19:25PM
I like this hint, especially the use of screencapture. It's amazing how automating even just one or two simple steps can really save you time. I made a similar Quicksilver-based utility a while ago that takes screenshots, optionally resizes them, and uploads them, via FTP, to the server that runs my blog. What used to be a simple but tedious job (so tedious that I would often forget one of the steps in my haste to get it over with) now goes boom-boom-boom.

---
Doc Drang
http://www.leancrew.com/all-this

[ Reply to This | # ]