How can I swap the primary display automatically in a dual-monitor setup?

Solution 1:

Update: I think I got it.

There's a utility called cscreen which lets you control the display settings. Running it shows all displays:

$ cscreen
DisplayID  Index     Depth     Width     Height  Refresh
 4249fef       1        32      2560       1440     0
 4248344       2        32      2560       1440     0
use -h to display all usage options

Sure enough, you can force one of them to be primary (with menu bar):

$ cscreen -i 4248344 -p

You can script setting the second screen as the primary like this:

$ cscreen -l | perl -lane 'print $F[0] if $F[1] == 2' | xargs -I id cscreen -i id -p

Now, to bind to a key, I first created an AppleScript script, SwapScreen.scpt:

swapscreen

Then I used QuickSilver to bind the script to a F13:

quicksilver

Now, when I plug in my MacBook, if the screens are messed up, I simply hit F13. Sweet!

Solution 2:

Been there, done that, with Mac Pro and 4 monitors. ;0

There is an odd bug/feature in OSX that makes default display settings privileged. This behavior has not changed with 10.9 and I believe is what is causing your problem. It is very poorly-documented and discussed on the web.

A permanent solution:

  1. Log on as the root user (you will have to temporarily enable it).

  2. Set the Display arrangement to what you want (as you show above)

  3. Log back on as whatever you like

It is somewhat non-obvious how to enable the Root User for interactive login, though not hard. Here is the official Apple guide:

http://support.apple.com/kb/PH113311

I would disable it when done for security reasons.

Solution 3:

It should remember the external setttings.

Did you try to swap the cables behind the monitor in order to invert the connection order? Maybe could do the trick.

A very easy solution is waiting one months and upgrade to OS X Mavericks, where you will have the possibility of having the menu bar and dock on both screen