How can I switch Dock configurations when an external display is connected?
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