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 is a detailed overview of this utility and how to use it, which allows capturing screenshots from the command line with ease.
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:
screencapture test.jpg
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:
screencapture ~/Desktop/screenshot.jpg
Send the Screen Shot to the Clipboard via Command Line
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:
screencapture -c
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 from Command Line
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:
screencapture -h
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.
Hello to all,
wondering if in Terminal, there’s a way to create screenshots every 2 minutes for over 1 or 2 hours.
And if possible, even from a part of the screen.
The reason I would like to do that is like in iTunes on a Radio Channel where the song name is announced to capture a screenshot, while I’m doing other stuff on my other machines.
Thnx in advance, Pasquinel
can i set the mailme to send automatically
No, doesn’t work. It generates the shutter click sound, but no file on the desktop. The errors are:
libpng warning: zero length keyword
libpng warning: Empty language field in iTXt chunk
Lance, this works to take screen shots from the command line, that why this is a feature of Mac OS X, it is built-in, it works on all versions of Mac OS X. The article explains clearly where the screen shot file ends up by default:
If you’re not familiar with the command line you probably shouldn’t be taking pictures from the Terminal, it will be overly confusing, you would have an easier time taking screen shots from the GUI like using the print screen method https://osxdaily.com/2010/05/13/print-screen-mac/
Perhaps your problem falls into the user error category. Maybe you entered improper syntax, or broke something if you are seeing libgpng errors, or maybe you rushed and didn’t follow the instructions.
[…] The screencapture command has a lot of other uses as well, you can read more about it here. […]
[…] timed screen shot feature was previously limited to the Terminal or Grab, but it’s pretty handy to have directly in Preview, with the countdown timer showing […]
Very useful thanks :)
Geek ville!