Take Screen Shots from the Terminal in Mac OS X
Aside from the keyboard shortcuts, Grab, and other screen shot apps, you can also take screenshots of your Mac OS X desktop directly from the Terminal with the ‘screencapture’ command. Here’s a quick overview of this utility and how to use it.
The Basics: Taking a Screen Shot from the Terminal in Mac OS X
First up, launch the Terminal (/Applications/Utilities/) and then type the following:
That is the most basic format of the command, it’ll take a screenshot of your entire screen and name it ‘test.jpg’ in the current working Terminal directory, which is typically your user home. You can always specify another location just by choosing a path for the screenshot, here’s the Desktop:
Send the Screen Shot to the Clipboard
If you want to send the screenshot to your clipboard rather than to a file, attach the -c flag, but don’t assign a file name or path:
Now that it’s in your clipboard you can just paste it into Preview, Photoshop, Pages, or whatever else you want to use.
Take a Screenshot on a Timer from Command Line
One of the better features of the Grab utility is that it lets you take screenshots on a timer, so you can setup an app or situation on the screen and capture things like alert boxes, menus, button actions, etc. You can also specify a timed screenshot from the Terminal:
screencapture -T 10 timedshot.jpg
The -T flag needs to be followed by whatever amount in seconds you want to delay the screen shot by, in that example, it’s 10 seconds which is also Grabs default.
Specify a Screen Shot File Type with screen capture
Make a note that the capitalization of these flags matters, if you use a lowercase -t, you’ll be trying to specify a file type for the screenshot instead, like so:
screencapture -t tiff sample.tiff
You can select a variety of file types to export to, including png, pdf, tiff, jpg, and gif.
Taking a Silent Screen Shot from the Command Line
If you plan on scripting out something with the screencapture command, you might not want the shutter sound to fire. To silently take a screen shot just use the -x flag:
screencapture -x quiet.jpg
This is a one time thing so you’ll have to always specify -x, it’s not a permanent change to make the screen shots silent.
Send the Screen Shot from Terminal to a New Mail Message
Another neat trick is sending the screenshot directly to a new Mail.app message:
screencapture -M mailme.jpg
This takes the screenshot, saves it as mailme.jpg, then automatically opens a new Mail message with that screenshot attached to it.
As with all command line tools, you can add the flags together to perform a variety of functions in a single command. If you want to see the other options available to you, just use the traditional -h flag with screencapture:
This will list out all of the available flags and what they do, and there are a variety of additional options available, like ditching the shadow, automatically launching in Preview, choosing Window Capture mode, and more. You can see a screen shot of the screencapture commands at the top of this post (redundant?).
If you really wanted to get creative, you could do things like setup an automatic mail a screenshot function based on Mac desktop events, or even assign a key to for the clipboard function and create your own Mac Print Screen button to duplicate that keyboard clutter that Windows users so dearly love, but those are topics for another post.
Finally, if you’d rather stick with the familiar Command+Shift+3 commands, don’t forget you can change the screen shot file type and save location, but that’ll require a quick trip to the Terminal as well. That command is the same in Mac OS X 10.7 and prior versions too.