Taking Screenshots from the Command Line in OS X

Posted by on Mar 9, 2010 in Geekery, Graphics, Mac | No Comments

camera.pngI was so impressed with this I had to share. I was looking for a way of taking screen shots of a user taking a screen shot. Yes, that’s a bit meta.

Basically, I wanted to grab some screen shots for a tutorial piece on how to capture screen shots on a Mac. So I wanted to shoot some screen shots which would actually capture pictures of the different cursor shapes you get — the cross-hairs, the little camera, and so on — while you’re capturing.

As is often the case on the Mac, this seemingly difficult task turned out to be dead easy. There’s a full command line interface for capturing screenshots that comes with OS X — I guess it may be what the GUI uses “under the hood” — and not only is it easy to use, but you can also capture cursors with it.

The command is “screencapture”, and it comes with many fine options, as you can tell if you run it with screencapture -h. There’s a full manpage available too, i.e. man screencapture.

Here’s the example I used to grab this shot:

screencapture -T5 -C test.png

The -T5 delays for five seconds — giving me time to trigger the GUI’s built-in screen shot facility and get the little camera cursor up on the screen — the -C tells it to capture the cursor as well as the screen, and the file name tells it where to save. If you have two screens and want to capture them both, just provide both file names.

There’s a ton of other options for kicking off different capture methods, changing the output file format, and so on. And this is all delightfully scriptable, of course. I’m sure this’ll come in handy for me at some point in the future, so I figured it was worth blogging in case it gives anyone else some ideas…

« Charity Appeal… | Normal Service Will Be Resumed »