How to get my screen responding again?

My MacBook Pro is running, ssh works fine, but the screen does not respond anymore.

The screen is frozen like the ice of Antarctica. The mouse does not move on the screen. The time of the clock does not change.

The Caps Lock light of the keyboard is responding.

Can you help me to get my screen responding again, please?

What I need is simply having my screen responding, in order to use my Mac and to continue what I was doing.


Solution 1:

Since you can ssh into the box, you can start killing processes one by one and eventually you will either reboot the box or free up the item that's holding the CPU / GUI frozen.

I would probably do these things in order of severity:

  1. Start a time machine backup before killing anything tmutil startbackup --block --rotation
  2. If I don't care to save work (since this kills all apps abruptly) - kill the loginwindow process and log back in.
  3. If I do care to save some work, kill all user processes not belonging to the user that needs to save work.
  4. Then kill all user processes that don't need work saved. (Apps and such)
  5. Then use AppleScript to tell each app that needs to save work to quit. (assuming the GUI isn't responsive at this point)

osascript -e 'quit app "Take Five" '

At this point, you'll either need to list the specific apps that you need to save work and ask if there are any ways to force a save (perhaps they use autosave and will recover all work anyhow) or just issue a restart / reboot command and get on with using the machine and recover what you can from your last backup.

Solution 2:

Killing WindowServer will get you out of most situations, but all GUI apps will die and restart with it.

The solution is to save data in all apps that don't do it automatically using Applescript
ps ax | grep -i appname
osascript save.scpt 6546, where 6546 is the PID of your app

The script will press Cmd+S and (optionally) Enter

on run argv
tell application "System Events"
    set theprocs to every process whose unix id is item 1 of argv
    repeat with proc in theprocs
        set the frontmost of proc to true
        delay 1
        keystroke "s" using command down
        delay 1
        # key code 36 # Enter
    end repeat
end tell
end run

P.S. This works from SSH session for apps like Sublime Text, but I can't figure out the way to tell the app to quit gracefully. It's either kill or reboot. The latter should take care of apps that support "Resume" feature.

Solution 3:

I know this is a late answer, and you may have already given up. I did a quick search and found that you can enable screen sharing (VNC) via SSH without AppleScript.

sudo  /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart \
-activate -configure -access -on -clientopts -setvnclegacy -vnclegacy yes \
-clientopts -setvncpw -vncpw mypasswd -restart -agent -privs -all

I copied that command verbatim from here. You want to omit the restart flag, I believe. Connect to your machine with a VNC client, save all of your work, and reboot the machine.