How can I switch Dock configurations when an external display is connected? I have a MacBook Pro that I use in two different 'modes', mobile and desktop.

Mobile is for when I'm using just the MBP with the integrated trackpad, keyboard, and display.
Desktop is for when I'm using it with external displays and an external keyboard and mouse, usually in clamshell mode.

A couple of facts have led me to look for a way to configure a different Dock to appear in each mode:


The resolution of the external displays is higher than that of the internal display, so I have more room for extra apps/folders/spacers in the Dock.
I generally use a different set of main apps in each mode.


So, is there a way to configure two different Docks in OS X and switch between them either automatically based on the presence of an external display or manually?
DockSpaces is nice and convenient, but annoyingly unscriptable. So, I wrote two little shell scripts, one to change to my desktop Dock and one to change to my mobile Dock.

The desktop script is triggered on arrival in my Home context in ControlPlane, and the mobile script is triggered by departure from it.
The desktop context is defined based on the presence of my external displays:


Here's how the scripts work:

I save a copy of both Docks in my Documents folder (the Dock configuration is stored in ~/Library/Preferences/com.apple.dock.plist).

When I switch from one to the other, I replace the appropriate file in my Documents folder with the current file in my Preferences so that changes I've made to the Dock are saved. Then I copy the alternate Dock from my Documents to my Preferences. Finally, the Dock process is restarted so that the changes take effect.

The Scripts:

To Desktop:

#!/bin/bash

cp ~/Library/Preferences/com.apple.dock.plist ~/Documents/Docks/mobile.plist
cp ~/Documents/Docks/desktop.plist ~/Library/Preferences/com.apple.dock.plist
killall Dock


To Mobile:

#!/bin/bash

cp ~/Library/Preferences/com.apple.dock.plist ~/Documents/Docks/desktop.plist
cp ~/Documents/Docks/mobile.plist ~/Library/Preferences/com.apple.dock.plist
killall Dock