0

I've wrongly opened the same question on StackOverflow. I hope to find a better explaination here.

I've seen in many pages (for example here: How do I find the windowid to pass to screencapture -l?) that you have to use the command: screencapture -l in order to capture a single window given its ID.

However when I try to enter screencapture -l into the terminal I get this error:

screencapture: illegal option -- l

I've checked a reference and actually I can't see -l as a possible attribute for screencapture: http://guides.macrumors.com/screencapture

How do you explain this? How can I solve this?

6
  • Can you add the full command you are trying to execute (and not just the error message)? And does it work if you open Safari and then copy/paste the command line from apple.stackexchange.com/a/56566/9058 ?
    – nohillside
    Sep 7, 2013 at 10:10
  • I've tried with screencapture -l, then screencapture -l idwindow a.png, then with safari open and pasted the code. Everytime the same error.
    – KingBOB
    Sep 7, 2013 at 10:16
  • Did you use AppleScript to get the window id ? Sep 7, 2013 at 10:20
  • I'm planning to. This time I've just used Quartz debug and used the "wid"
    – KingBOB
    Sep 7, 2013 at 10:21
  • It's strange because I can't find the option -l in the references. ss64.com/osx/screencapture.html
    – KingBOB
    Sep 7, 2013 at 10:22

1 Answer 1

1

The -l option requires an argument for the ID of the window:

$ screencapture -l
screencapture: illegal option -- l
usage: screencapture [-icMPmwsWxSCUtoa] [files]
  -c         force screen capture to go to the clipboard
  -C         capture the cursor as well as the screen. only in non-interactive modes
  -d         display errors to the user graphically
  -i         capture screen interactively, by selection or window
               control key - causes screen shot to go to clipboard
               space key   - toggle between mouse selection and
                             window selection modes
               escape key  - cancels interactive screen shot
  -m         only capture the main monitor, undefined if -i is set
  -M         screen capture output will go to a new Mail message
  -o         in window capture mode, do not capture the shadow of the window
  -P         screen capture output will open in Preview
  -s         only allow mouse selection mode
  -S         in window capture mode, capture the screen not the window
  -t<format> image format to create, default is png (other options include pdf, jpg, tiff and other formats)
  -T<seconds> Take the picture after a delay of <seconds>, default is 5
  -w         only allow window selection mode
  -W         start interaction in window selection mode
  -x         do not play sounds
  -a         do not include windows attached to selected windows
  -r         do not add dpi meta data to image
  -l<windowid> capture this windowsid
  -R<x,y,w,h> capture screen rect
  files   where to save the screen capture, 1 file per screen
$ screencapture -l $(osascript -e 'tell app "Safari" to id of window 1') test.png
$

Or if you have an older version of OS X, screencapture might not include the -l option. At least in 10.8 the -l option is only shown in the help message and not on the man page.

osascript -e 'tell app "Appname" to id of window 1' doesn't work with all applications, but see these questions for other ways to find the IDs of windows:

5
  • Is there any way to use it if I'm on a 10.5.8?
    – KingBOB
    Sep 7, 2013 at 10:24
  • I'm not an expert by any mean but what if I get somwhere an updated version of screencapture command and I just replace mine in: /usr/sbin/screencapture?
    – KingBOB
    Sep 7, 2013 at 10:26
  • I uploaded the /usr/sbin/screencapture from my installation of 10.8 here, but I'm not sure if it will work.
    – Lri
    Sep 7, 2013 at 10:37
  • Nope! Now it's not working at all haha it gives me "Illegal instruction"
    – KingBOB
    Sep 7, 2013 at 10:48
  • I found windowid of Safari: 4656 So I typed command like this: screencapture -l 4656 ~/Desktop/test.png but nothing happened Any suggestion ?
    – hoangpx
    Mar 7, 2016 at 23:23

You must log in to answer this question.

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