Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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
add comment

2 Answers 2

up vote 7 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 developer.apple.com/downloads) if you run defaults write com.apple.QuartzDebug QuartzDebugPrivateInterface -bool true.

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

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
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
add comment

Your Answer

 
discard

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.