I'm trying to use screencapture from the terminal, when logged in over ssh, to a mac that has no screen attached. I can screen share to the machine, so I'd like to capture the same display.

However when I try it, I don't get an image file.

Here's what I've tried...

screencapture -tpng /Users/slomojo/Desktop/image.png


sudo screencapture -tpng /Users/slomojo/Desktop/image.png

and finally,

sudo launchtl bsexec $(ps -ax | grep loginwindow.app | awk '{print $1}' | head -1) /usr/sbin/screencapture -tpng /Users/slomojo/Desktop/image.png

None of which work... (note that the last attempt is getting the PID for loginwindow.app and attaching the screencapture process to it as suggested by the OS X man page.)


FYI I'm running OS X 10.6.8.

Additional update.

I didn't mention that the machine doesn't have a screen attached, (I usually connect to it via VNC/Screen Sharing) I jumped to another machine on that network and the command works ok, (of course I guess!)

I should also mention that, as I'm logged in on the remote machine on the same account as the local GUI session, the first version of the command works fine.

In fact, just the following without all the launchctl stuff works fine:

screencapture -tpng ~/Desktop/image.png

However, I still need to figure out how to screencapture on the headless machine, ie. capture the same display I'd see over screen sharing.

I'm not 100% sure, but I think that the screen sharing session may create/teardown a virtual screen device when it's connected/disconnected. So I'll try to do the screencapture when I can get a screen sharing session running at the same time.

Update #2

I tried doing the screencapture while another machine had a screen sharing session open on the same user account as the ssh session, no dice.

However, interestingly enough I was in the same room as all the boxes in question and the target box made the "shutter" sound when I ran the screencapture remotely.

Looks like it's not possible to screen grab on a displayless mac, without some serious additional work, I will VNC to it remotely instead.

  • The final one should work, if you change the path to /usr/sbin/screencapture - yours is missing sbin/. Commented Aug 29, 2011 at 3:26
  • @Ingmar hupp - Sorry, that was a typo in the question, I'm already using /usr/sbin/screencapture.
    – ocodo
    Commented Aug 29, 2011 at 4:09
  • 1
    I tried this; it worked only when the user was logged in, i.e. it didn't work when the login screen was showing Commented Aug 29, 2011 at 6:46
  • User is logged in, actually I'm ssh'ing in on the same user name, the only possible issue is that there is no screen attached. I'm going to ssh to another box local to it that does have a screen and see if that's the issue.
    – ocodo
    Commented Aug 29, 2011 at 23:51
  • @Samantha, yes, that was the issue, any ideas how I can get the virtual screen (ie, the screen sharing display) to capture, the docs for screencapture are pretty thin.
    – ocodo
    Commented Aug 30, 2011 at 0:00

1 Answer 1


I'm not sure if this will work, but, it's worth a shot...

What is you create an Automator script to take a screen capture, and then run that using the terminal?

Similar to what is described in this TUAW article, however, without the part that mails the screen capture to you.

TUAW Example

Save the Automator script as an application, SSH in, and run open /path/to/the/automator.app

  • I'll give it a go. BTW, one thing I already tried, which I should record here: using osascript to send the Cmd-Shift-3 screen capture shortcut, it didn't work.
    – ocodo
    Commented Sep 9, 2011 at 0:11

You must log in to answer this question.

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