Pragmatism in the real world

Screenshot of the active window on Mac

I find myself needing to take screen captures of the currently active window in OS X reasonably frequently. The built-in way to do this on a Mac is to use shift+cmd+4, then press space and then use your mouse to highlight the window and click.

For a good proportion of the time, I’m not using a mouse, so this doesn’t work great.

There’s a built-in command line utility called screencapture which requires you to know the Quartz window id of the window you want to capture, so it’s now a multi-step process to just take a screenshot of the currently active window.


Fortunately, there’s a little open source utility called QuickGrab which solves this. (The binary quickgrab is in the repo, so you don’t have to compile)

As an aside, that link is to my fork which fixes Chrome. A friend recently discovered that the current master version fails to take screenshots of Chrome if it’s the active window. When I investigated, I discovered that it’s because Chrome creates an invisible window at the top of its stack which needs to be ignored when looking for the active window. That’s what my update does.

QuickGrab is really easy to use. From the command line you simply do:

$ sleep 2 ; quickgrab -file ~/Desktop/Screenshot-`date '+%Y%m%d-%H%M%S'`.png

This is a faff.

Enter Alfred

Alfred is little app that can run commands for you from a text window or via a hotkey, so this is what I use to trigger QuickGrab.

I have a keyword of screenshot set up:

Screen Shot 2016 07 20 at 13 40 58

To use, I ensure that I have the window I want to capture active and then activate Alfred, type screenshot and press return. This then creates a PNG file with a name similar to Screenshot-20160724-1124429.png on my desktop.

I also set up a hotkey for cmd+§ (finally a use for that § key!) which does the same thing.

I’ve created Screenshot.alfredworkflow which does all this, so simply download it and install it into your Alfred and you’re good to go! This workflow includes the quickgrab binary, so you don’t need to get it separately.

You can, of course, edit the workflow once you’ve installed it to change the keyword and the shortcut key to something else, should you want to.

3 thoughts on “Screenshot of the active window on Mac

  1. Sorry for commenting on a seven-year-old post. :)

    I stumbled upon this page when Googling for a solution to capture a window. I like the hacky way you solved this. I found another solution that is integrated into macOS here:

    In short:
    To capture a specific application window, press and hold Command-Shift-4 then tap on the Spacebar.
    To copy a specific application window, press and hold Command-Control-Shift-4 then tap on the Spacebar.

    If you don't want to use the mouse, pressing enter captures or copies the current selection.

Comments are closed.