How can I switch Dock configurations when an external display is connected?
Solution 1:
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
Solution 2:
I found a manual solution, Dock Spaces. It will cost you a little bit under $8, though. Hopefully that's not an issue.
As for automating it, I'm not sure if it is scriptable or not, but it does not have automation like this built-in.
Solution 3:
DockSpaces is the answer to your question. DockSpaces allows you to create docks with different applications in each dock. It does not have the automation built in, so I would recommend to you an application that you recommended to me, ControlPlane. You should be able to change docks based on the presence of an external display.