26

The command line utility screencapture claims to be able to capture a single window without requiring interaction, but I can't figure out what to pass it.

-l<windowid> capture this windowsid

It's not the process id of the the application.

22

For some applications you can use AppleScript:

screencapture -l$(osascript -e 'tell app "Safari" to id of window 1') test.png

It doesn't work with Chrome though.

The IDs are also shown in Quartz Debug (available from developer.apple.com/downloads) if you run defaults write com.apple.QuartzDebug QuartzDebugPrivateInterface -bool true.

  • 1
    Unfortunately, this doesn't work with non-Applescriptable apps like Eclipse or Google Chrome. – CajunLuke Jul 16 '12 at 18:52
  • Yeah, my target app is not Applescriptable :( But thank you anyway. – Gareth Simpson Jul 16 '12 at 19:13
  • 2
    Note that window ids are not guaranteed to correspond to the Quartz window id even in applications that are scriptable. – Chris Page Aug 11 '12 at 5:23
  • Quartz debug seems to no longer exist or else it has been renamed or bundled? – gman May 31 '18 at 3:37
  • Quartz Debug is included in "Additional Tools for Xcode" available at developer.apple.com/download/more. – Nicholas Riley Nov 23 at 15:53
9

I wrote a little command line utility to retrieve the Window ID for apps that don't support AppleScript. Get it here: https://github.com/smokris/GetWindowID

You can then capture a specific window by specifying its bundle name and window title:

screencapture -l$(./GetWindowID "Vuo Editor" "untitled composition") VuoEditorWindow.png
  • Hi, I'm trying to use it but I'm not sure on what I'm doing. I've downloaded the Makefile,GetWindowID.m. But when I launch the command ./GetWindowID.m it gives me this error:./GetWindowID.m: line 4: syntax error near unexpected token (' ./GetWindowID.m: line 4: int main(int argc, char **argv)' – KingBOB Sep 6 '13 at 22:25
  • 1
    @Giorgio: Open a Terminal window and change to the folder that contains Makefile and GetWindowID.m, then run the command make. It will produce a binary called GetWindowID, which you can then invoke using the command I described in my answer. – smokris Sep 24 '13 at 4:37
6

I wrote a command line utility that wraps over screencapture and the Quartz windowing library.

Grab it here: https://github.com/thismachinechills/pyscreencapture

Use it like this:

./screencapture.py Chrome -t Stack Overflow
  • Have you missed double-quote? – kenorb Aug 17 '15 at 8:36

You must log in to answer this question.

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