Can I configure my Macbook to unmount all external drives when I close the lid?
There are a number of apps that can run scripts on sleep:


SleepWatcher — simple yet effective.
Scenario — can also run scripts at other times such as after wake.
ControlPlane — more customisable, lets you run scripts after many different events.


A bash script such as the following will unmount all specified disks:

VOLUMES="/Volumes/drive1 /Volumes/drive2 /Volumes/drive3"
for volume in $VOLUMES ; do [ -d $volume ] &amp;&amp; umount -f $volume done


To unmount all volumes except /:

umount -A


or more cleanly…

osascript -e 'tell application "Finder" to eject (every disk whose ejectable is true)'