Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 14 down vote accepted

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 if you run defaults write QuartzDebugPrivateInterface -bool true.

share|improve this answer
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
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

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

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

screencapture -l$(./GetWindowID "Vuo Editor" "untitled composition") VuoEditorWindow.png
share|improve this answer
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)' – Giorgio Sep 6 '13 at 22:25
@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

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

Grab it here:

Use it like this:

./ Chrome -t Stack Overflow
share|improve this answer
Have you missed double-quote? – kenorb Aug 17 '15 at 8:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.