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.
tell application "System Preferences"
set current pane to pane "com.apple.preference.displays"
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"
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:
- Make sure the AppleScript doesn't show a startup dialog