autorandr and dockd have been around for a while. Both let you automatically switch to or from external displays when your laptop is plugged into a hub or hooked up to a docking station. But those are largely Linux- and Thinkpad-centric solutions. Let's do it the FreeBSD way.

Here are my requirements. I have an E-series Dell laptop with a docking station. My docking station is hooked up to one large Dell monitor. When the laptop is attached to the docking station, I want...

  1. The laptop to use the larger, external monitor exclusively (no mirroring)
  2. The default sound device to switch to the external monitor's speakers
  3. Disable automatic locking via xautolock(1)
  4. Disable suspend on lid close

When the laptop is removed from the docking station, I want...

  1. The laptop to switch to its internal display
  2. The default sound device to switch back to the internal laptop speakers
  3. Automatic locking to re-enable
  4. Suspend on lid close to re-enable

To do this we'll need the following:

  1. devd(8) for launching userland applications when kernel events occur
  2. xrandr(1) for switching displays
  3. xautolock(1) for automatic locking
  4. sysctl(8) for changing hardware knobs
  5. Some core utilities and a tiny shell script to bring it all together