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:
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.
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.