Exchanging primary/secondary display in OSX via shortcut

This has bothered me for quite a while: Since I am attaching and detaching different displays/projectors for several times a day (moving from one class to another, coming to work, back at home etc) I very often had to echange the primary and the secondary display in OSX via the system preferences and dragging the menu bar from one display to the other and vice versa.
systemPreferences_display_osx
I spent quite some while on google to find a (shortcut/applescript/terminal/…) way to do this quickly, no success.
I am using MarcoPolo for setting several settings automatically based on my current position/wifi/daytime/.. but you guess it – the primary and secondary display settings are not setable from MarcoPolo neither.

Finally today I stumbled upon a posting on a messageboard from 2006 that mentioned an (old) 52kB command line tool called cscreen that should be able to do what I was looking for. After spending some more time at google I found documentation for cscreen as well as the program itself.
I created an app with Automator and now can finally switch the displays either via Quicksilver or with MarcoPolo as well.

In case somebody is looking for the documentation I will re-post it here, just in case the one on the messageboard gets lost some day:

Changing screen settings with cscreen
 
Usage: cscreen [-d ] [-x ] [-y ] [-r ] [-s ] [-v] [-m] [-f] [-l] [-h]
[-d ] : specifies the bit depth (bits per pixel)
[-x ] : specifies the width in pixels
[-y ] : specifies the height in pixels
[-r ] : specifies the refresh rate in Hz
[-s ] : specifies which display to use (defaults to main display)
use a as the option to -s to specify the action on all displays
[-v] : display valid modes (use -s to specify display or nothing for the default)
[-m] : require an exact match
[-f] : forces settings (ignores safety mechanisms; USE AT YOUR OWN RISK)
[-l] : lists the current displays and modes
[-p] : sets the requested display to have the menu bar
[-h] : displays the usage
 
Note: Using -p will change the display index so you will likely want to use -l again to show the current displays if you wish to use -p a second time.
 
So for example, if you place cscreen in the Utilities folder and you want to change the resolution to 1024x768, you'd send:
 
/Applications/Utilities/cscreen -x 1024 -y 768

Update: As Eric mentioned further down, there is a new version of cscreen available that is Mountain Lion compatible. Thx!


About this entry