I've had some problems with a Xserve having a garbled screen (see image) when I log in to it, and since there is no monitor connected, there are no tricks for pressing "detect display" to use for resetting the display. And I'm using it blindly as well, so I needed a way to do it from the terminal. So I put together the below AppleScript that fixes the issue for me.
detect_displays
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.displays"
end tell
tell application "System Events"
tell process "System Preferences"
select row 1 of table 1 of scroll area 1 of group 1 of tab group 1 of window "Displays"
end tell
end tell
Basically, all it does is open the system preferences and selects the smallest resolution (the first in the list) which makes the system reset the display and fix the screen. Save this script as an application on the remote machine and run it with "./detect_displays.app" from the terminal.
Hopefully this will help someone that was having the same problem as me.
For this to work, you need to make sure of this:
- Enable System PreferencesUniversal AccessEnable access for assistive devices
- Make sure the AppleScript doesn't show a startup dialog