6

I have a certain location on my screen that I would like to take a screenshot of rather frequently for a project. Is there a way to set a key binding that would allow one to press a certain combination of keys that will grab that region and output it to a PNG?

4

Keyboard Maestro can do this with a macro such as…

               

14

This is quite easy to do.

The Built in Screencapture has a command line option to capture a rect area. This is a rectangle with a screen coordinate point, width and hight, x,y,w,h

We can use this in an Automator.app Service workflow and then give the service that it creates a hotkey/shortcut in the keyboard services system preferences.

First we create the Service workflow in Automator.

Open Automator and a new Service Workflow document.

Set :

service receives: none In : Any Application

Add a Run Applescript action.

Type or paste this code into the Run Applescript action, replacing the default code.

  set theDate to do shell script "date +%Y_%m_%d_%H%M%S"
set theTempPath to POSIX path of (path to desktop)
set thePath to theTempPath & "screenCapture_" & theDate & ".png"


do shell script "screencapture -R320,210,848,440 -tpng" & space & quoted form of thePath

enter image description here

The code above will create a timestamp string to add onto the end of the file name.

This serves two purposes, 1, you can visually see when they where taken, 2 and more important, the files will no be overwritten by the next capture as the name will be different.

-R320,210,848,440 is the Rect option: x,y,w,h

-tpng is the file type format option: png

& space we need a space between the options and the next part of the command.

**&quoted form of" escapes spaces and illegal characters that the command line will error at if we do not guard against them.

& thePath adds the file output path which includes the file name

The ampersands & are applescript syntax to say this and this.


Save the Service. You will be prompted to give it a name.

Now open the system Preferences and go to the keyboard system pref. Then the Shortcuts Tab and finally the services selection panel.

enter image description here

Scroll right down to the bottom to the General group

Select your service and give it a shortcut. ( remember to use one that does not clash with any other apps you have that use shortcuts: I show I used Cmd + shift +R, but I changed it in mine as I found a clash with Safari reader shortcut)

In most cases the shortcut will be picked up by apps straight away but some may need to be closed and reopened.


An aside:

The files are set to land on the desktop.

You can change this in a couple of ways.

But to save me adjusting this for everyone, the easiest thing to do is add a move finder items action

First add this bit of code to the end of the code above:

return (POSIX file thePath) as alias

This will pass on the file path to the next Automator action.

Then add a move finder items action and choose your destination from it's dropdown menu.

enter image description here

  • I see you set your Automator Service to ⇧⌘R however it's used by AirDrop and will be in conflict when the Finder or Desktop has focus. – user3439894 Oct 17 '15 at 8:56
  • 1
    Thanks, And Safari. I change mine to something else. I was not suggesting what shortcut people use. As There are too many apps out they that individuals use that what ever I suggest may clash with – markhunte Oct 17 '15 at 9:19
  • 1
    You have an interesting definition of "quite easy"! – Mark Henderson Oct 17 '15 at 11:36
  • 1
    @MarkHenderson it is easy. It not using any third party app. And the only thing you need to work out is your rect. The screens 0,0 point is Top left. Which is the x,y. You workout how far right from the left edge. This is the x, How far from the top edge, This is the y. The x,y form a point. The you work out your width from that point and your hight from that point. The forms your rect. All just because it is a long post does not mean it is a long process to set up. It should only take a couple of minutes. – markhunte Oct 17 '15 at 13:21
  • 1
    @ylluminate no problem, not everyone wants to use third party apps when the built in ones can do the something. :- ) For myself I can setup so I can enter a different rect if I want without redoing it in the service. But thats a little bit more involved than was needed here. – markhunte Oct 17 '15 at 14:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .