Escape black screen on MacBook Pro after disconnecting external display
Here's the scenario:
In my office, my MacBook Pro (Early 2011, running 10.10) is plugged into an external display over DisplayPort. I disconnect the laptop, close it (putting it to sleep), and take it with me. When I arrive to my destination I find that opening the laptop wakes it up to a black screen– however it is awake:
- Backlight is visibly on
- Volume controls work (I can hear it, no visuals)
The simplest way to solve this is to either restart or go back and plug it in to a monitor and retry the sequence of disconnecting to ensure this doesn't happen. Neither of these are feasible at the moment for various reasons. Session details:
- Multiple users are logged in
- Assume that some files are not saved or that progress may be lost by restarting (I think I'm safe here, but it's good for the exercise)
- All users have a password protected lock screen upon awakening (though I am aware of the current user and password)
- I have access to the shell which can be confirmed by opening iTerm (via shortcut) and entering "say hello"
Some of the suggestions I've seen for resolving this without a restart involve "Detect Displays" but unfortunately that's a bit too difficult to get to in the GUI without any visual feedback. All that being said, are there any creative ways to escape this using either the command line, AppleScript, or even guess-and-click if completely necessary?
I found this on Stack Overflow, to invoke 'Detect Displays' - which you could include in an Automator Service & then give a key command.
Of course… it would only be good for next time it happened, not this.
tell application "System Preferences"
activate
reveal pane "com.apple.preference.displays"
end tell
delay 0.5
tell application "System Events"
tell process "System Preferences"
try --don't even consider not using a try block!
key down option
delay 0.2
click button "Detect Displays" of window 1
delay 0.2
key up option
on error --logging out is the only other way to clear these
key up option
end try
end tell
end tell