Skip to content

Instantly share code, notes, and snippets.

@jfonte
Created July 5, 2016 16:27
Show Gist options
  • Save jfonte/2f85d5745a5d6065efd576d86e4282ae to your computer and use it in GitHub Desktop.
Save jfonte/2f85d5745a5d6065efd576d86e4282ae to your computer and use it in GitHub Desktop.
#!/bin/bash
# sleepwatcher script to dismount ext. drives on wake https://www.kodiakskorner.com/log/258
# checks if data & bak volumes are mounted, and if so dismounts
if [[ $(mount | awk '$3 == "/Volumes/bak" {print $3}') != "" ]]; then
diskutil umount bak
fi
sleep 3
if [[ $(mount | awk '$3 == "/Volumes/data" {print $3}') != "" ]]; then
diskutil umount data
fi
sleep 3
# tries to eject drive and displays error if in use
if ! diskutil eject bak ; then
osascript -e 'tell app "System Events" to display dialog "ext drive in use"'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment