Detect Displays

OK so I picked me up a powerbook and it works great BUT when I change monitor arrangements (like hook it up to tile with my desktop monitor) and fire up the machine, I always have to go to the system prefs/displays panel and click on the “Detect Displays” button. Only then is the second monitor recognized and the desktop set up correctly.

So what I want to do is create a little app to run on start up that will do this for me. The following was my first guess. No luck. No errors.

tell application "Finder"
	open file (((path to system folder) as string) & "Library:PreferencePanes:Displays.prefPane")
end tell

delay 3

tell application "System Events"
	tell process "System Preferences"
		tell button "Detect Displays" of group 1 of tab group 1 of window "Color LCD" to click
	end tell
end tell

Any suggestions?

Dave

According to this discussion on the Apple site, this will work. I have only one display so I am unable to confirm that it works.

tell application "System Preferences" to activate

tell application "System Events"
	tell process "System Preferences"
		click menu item "Displays" of menu "View" of menu bar 1
		delay 3
		tell button "Detect Displays" of group 1 of tab group 1 of window "Color LCD" to click
	end tell
end tell

– Rob

Well, with that one I get a

It appears that the culprit is the line

click menu item "Displays" of menu "View" of menu bar 1

I get around that by opening the pref panel itself. But then that “tell button…” line doesn’t seem to be working either.

Do you have Apple’s GUI Scripting software installed? If so, after installing it did you go to the Universal Access pref pane and “Enable access for assistive devices”? Both are required for the script in question.

– Rob

Sweet!

I didn’t know about the “… assistive devices” setting. It works now.

Thanks Rob!