2

I'm trying to tinker with a machine where I can only connect via shell. I don't have physical access and can't access VNC (maybe that's another question). I'm trying to take a screenshot right now to see what's going on, using screencapture over ssh, but it doesn't save the screenshot. No error message or anything. And there's no verbose mode for screencapture, so I can't diagnose it easily.

This is what happens when I try to take the screenshot:
Rogers-iMac:screenshots roger$ screencapture 0911.png
Rogers-iMac:screenshots roger$
(returns to shell and outputs nothing)

Rogers-iMac:screenshots roger$ ls -la total 0 drwxr-xr-x 2 roger staff 68 Sep 11 19:56 . drwxr-xr-x+ 32 roger staff 1088 Sep 11 19:56 .. Rogers-iMac:screenshots roger$


EDIT: Beroe has suggested that being connected through SSH is a factor. I've edited my question to reflect the fact that I am doing this all over SSH. Unfortunately, screencapture still fails silently even when I follow the instructions given in the man page:

Rogers-iMac:screenshots roger$ ps -axww | grep loginwindo[w] 82 ?? 0:05.10 /System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow console Rogers-iMac:screenshots roger$ sudo launchctl bsexec 82 screencapture 0915.png Rogers-iMac:screenshots roger$ ls -la total 0 drwxr-xr-x 2 roger staff 68 Sep 11 19:56 . drwxr-xr-x+ 32 roger staff 1088 Sep 15 10:17 ..

1
  • Can you use the AppleScript solution? That worked for me. Wouldn't be hard to move the file it generates to a new directory.
    – beroe
    Sep 15, 2014 at 22:13

1 Answer 1

2

You are ssh'd to the machine and trying to get a picture of the screen?

Using AppleScript, it won't let you generate the file name, but you can at least save a screenshot to your Desktop folder:

osascript -e 'tell application "System Events" to keystroke "#" using command down'

The "right way" using screencapture doesn't work when you are remote... There is this caveat in the documentation:

SECURITY CONSIDERATIONS To capture screen content while logged in via ssh, you must launch screencapture in the same mach bootstrap hierarchy as loginwindow:

 PID=pid of loginwindow
 sudo launchctl bsexec $PID screencapture [options]

LATER: I have tried to get this to work remotely... You can get the PID of login window looking at the first number in this output:

ps -axww | grep loginwindo[w] 

However the command still does not seem to take...

2
  • 1
    Even if you're still trying to troubleshoot a solution, it is helpful to know that being connected remotely makes a difference. I'm going to add that info in the title. Sep 15, 2014 at 15:36
  • 1
    Using the applescript command doesn't work. Exits with no error, but nothing appears in my desktop. Sep 16, 2014 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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