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 screencapture utility has a -w switch which allows capturing the front window, but only after highlighting the window and getting a click from the user.

Is there any way to capture the front window non-interactively using some shell command?

share|improve this question
I can't find any screenshot command on my Mac running OS X 10.8.3. Is it an addition you've installed? Which is your OS version? – jaume May 16 '13 at 12:47
@jaume corrected to screencapture – GJ. May 16 '13 at 16:45

The -l option allows capturing a window by ID. It is only shown in the help message and not on the man page.

I don't know any way to find the window IDs that would work with all applications though. This doesn't work with Preview, Activity Monitor, or Chrome:

screencapture -l $(osascript -e 'tell application (path to frontmost application as text) to id of window 1') /tmp/screencapture.png

share|improve this answer

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.