Setting resolution, refresh rate, other display stuff via AS

I’m on a PowerBook that gets deployed in a wide variety of settings, often using an external monitor (big honkin’ CRT, presentation projector, DVI, etc) as the primary display, in other places & times using one as auxiliary (smaller CRT, etc).

Sometimes I hook up and boot and the OS erroneously tries to drive the external at some combo of resolutution + refresh rate that it doesn’t support, and if it really wants to add insult to injury it makes that one the primary display. Boy is that ever fun.

Last time, I fixed the problem by disconnecting the monitor and nuking the files “windowserver.xxxxxxxxxxx.plist” and “preference.displays.xxxxxxx.plist”
in ~/ and also the file “com.apple.windowserver.plist” in /Library", rehooked the monitor and rebooted. Got the screen back at the expense of all my settings for all my various monitor configurations. :frowning:

I’ve been playing around with GUI scripting and have the following working:


tell application "System Preferences"
	activate
end tell

tell application "System Events"
	tell application process "System Preferences"
		set frontmost to true
		click menu item "Displays" of menu "View" of menu bar 1
		click menu item "Display" of menu "Window" of menu bar 1
	end tell
end tell

That (in case it isn’t obvious) peels open the Display prefs and puts me on the window for the (black, wrongly-rezzed) external monitor.

I can’t figure out how, via AppleScript, to make the scrollable list of possible resolution and refresh-rate choices active, or to set the value to a specified desired combo of horizontal vertical and refresh. In the mean time I have incorporated the above-cited AppleScript into a QuicKeys macro followed by a pair of QK clicks — the first to make the scrollable list active so that I can use the arrow keys to switch to a different setting even in the dark, as it were, and confirm each change (even if it’s equally wrong) so I can keep going until I hit something the monitor can use. Klunky and awkward but functional.

Suggestions for a more elegant approach?

It would be nice to be able to bypass SysPrefs and issue something more imperative like


tell the application "System Events"
  activate
  set the display parameters of monitor 1 to "1024 x 768 x 32 @ 85"
end tell

Except of course that it should work.

I can’t be the only person who has needed to AppleScript-coerce the monitor settings of their Mac. (It was common enough under MacOS 9). How’s it done?

To state the more obvious first …
In the Display Preference Pane, you can check “Show displays in menu bar” that will put a display item on the menu bar for selecting resolution/color combinations. Using it is as easy as running a script.

I believe that the Jon’s Commands OSAX has commands that allow you to get and set the display attributes directly from a script. It can be found in the OSAX section of this site.

To correct the error first: you misunderstand. I hook up external monitor and boot. OS thinks the external monitor should be the main monitor (i.e., the one with the menu bar, the disk icons, and so forth). OS also thinks the external monitor should be driven at some combo of resolution and refresh rate that this particular monitor does not support.

Therefore there is no visible menu bar. There is a blank black external monitor and there is an empty TFT screen that I can get my mouse arrow onto and that’s it.

I unhook the external monitor and I’ve got icons, menu bar, disk icons, and so forth all on the TFT, but I cannot at this point set the parameters for the external monitor because there isn’t one, dig?

The problem is that in some configurations (my main work configuration) the external monitor really is the main screen because I’ve got a nice big high-res Trinitron and it sits in front of me, PowerBook off to the side, external keyboard and mouse between me and the big Trin, big Trin set to a resolution that not just any old monitor happens to support. But being a PowerBook it goes other places and I hook up other devices (including a presentation projector in a conference room) where I want a different configuration to hold true.

MacOS is pretty smart about this kind of thing usually and will usually apply the correct setting on-the-fly simply by recognizing the equipment. (“Oh, you’re in the conference room, I know this projector monitor, you want it at 1024 x 768 x 32 at 75 MHz and you want it on the left and you want it to have the menus and icons, no problem”). But sometimes it gets it wrong. Sometimes when it does get it wrong, it’s still no problem as long as whatever screen’s got the menu bar is working with the settings the MacOS tosses at it.

But when it puts the menu bar on the external and the external stays black because the config is wrong for it, that’s just no fun at all.

Come to think of it, an AppleScript that would simply make the internal TFT the main screen would fix a lot of ills; if I could do that at will, I’ve got access to the settings.

Now…Jon’s Commands, you mention. OS X compatible? I thought they were only avail for OS 9.

Take a look at this thread:

http://bbs.applescript.net/viewtopic.php?t=9000

Jon