Friday, October 03, 2008

OS X Tip: Storing Screencaptures in a Different Folder

You may be familiar with the keyboard shortcuts Cmd-Shift-3 and Cmd-Shift-4 to do screen captures in OS X. The "3" shortcut takes a picture of the whole screen. The "4" shortcut lets you drag an area to capture. By default, the screen captures are stored in your Desktop folder. Adding the Ctrl key to the key sequence puts the result on the clipboard.

But what if you want to store the pictures somewhere else?

With the Mac's eye-catching GUI, it's easy to forget there's a real UNIX system under the hood. You can invoke the screen capture feature from the Terminal command line with the screencapture command:

screencapture ~/pic_in_home_directory.jpg # Waits a few seconds, then captures full screen
screencapture -iW /tmp/pic_in_some_other_directory.jpg # -i = use mouse to select; -W = capture full window

There are other options you can use, like -c to send output to the clipboard, or -t to set the output filetype. (I've got my system set to save JPGs by default, so I didn't use -t jpg in the examples above.)

In the UNIX shell, you could use the alias command to run screencapture with a preselected set of options. But that still forces you to specify the full path to the file on the command line, or switch to the directory where you want the file stored.

A more convenient technique is to use shell functions, which let you pass parameters. For example, here I create 2 commands I can use to take screen captures. blogsnap foo puts the output in foo.jpg in a predefined folder. clipsnap sends the output straight to the clipboard. mailsnap sends the output straight into a new mail message.

blogsnap() {
screencapture -iW ~/documents/Blogs/Screencaps/$1.jpg
}

clipsnap() {
screencapture -icW
}

mailsnap() {
screencapture -iWM /tmp/$$.jpg
}

You can paste the commands below straight into a terminal window to define those commands temporarily, or put them into the shell initialization file (depending on the shell, typically .profile, .bashrc, or .kshrc) so that they're available in each new Terminal window.

No comments: