Take Screenshot Directly to Preview

Okay this is my first foray in to AppleScript, and I have to say that I don’t hate it. I wanted a way to take screenshots directly in to Preview on my Mac.

Turns out that the screenshot utility is available on the command line:

> screencapture -h
screencapture: illegal option -- h
usage: screencapture [-icMPmwsWxSCUtoa] [files]
  -c         force screen capture to go to the clipboard
  -b         capture Touch Bar - non-interactive modes only
...

Thats’s nice and clean. So you want to run this as a script, and Macs give you a way to do that.

Rob Griffiths posted this script just so I didn’t have to think about it. Some editing changed the format to what I wanted.

do shell script "DATE=$(echo `/usr/local/bin/gdate +%a-%b-%d-%H-%M-%S`);
    FILE=~/Pictures/screenshot-${DATE}.png;
    screencapture -i -x $FILE;
    if [ -e $FILE ]; then
    open /Applications/Preview.app $FILE;
    fi"

This is more than I could have hoped for because it neatly organizes my screenshots too. Now you just have to make an automator script like so:

[

… and then configure a keyboard shortcut to run that service you just created.

[

And now you can take sexy mac screenshots for use in your blog as well.

Edit: I think I forgot to mention how to take the pretty screenshots for the Mac windows. Shift+Command+4 then Space will turn your cursor in to a camera so you can select windows.