screencapture command on mac fails silently when sshed in

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 ..

Roger Filmyer

Posted 2014-09-12T00:01:28.483

Reputation: 121

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 – 2014-09-15T22:13:22.860

Answers

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...

beroe

Posted 2014-09-12T00:01:28.483

Reputation: 881

1Even 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. – Roger Filmyer – 2014-09-15T15:36:02.907

1Using the applescript command doesn't work. Exits with no error, but nothing appears in my desktop. – Roger Filmyer – 2014-09-16T13:42:35.317