SleepWatcher: Mac housekeeping before going to bed

sleep.jpg
If you have ever mounted a network volume you'll know that chances are if the Mac goes to sleep it won't remount the volume when it wakes up. This is a pain for me because I have all my music on a single samba share, using SleepWatcher ensures that volume is always mounted when I wake my Mac from its slumber.

To perform tasks at the sleep/wakeup moment create .sleep and .wakeup files in the user's directory (e.g. /Users/david/.wakeup). These files are just plain old shell scripts so you can do anything you like within them, just ensure you mark them executable by the user. Below is my .wakeup file which I have symlinked to .sleep, it mounts my music volume (on the server SERENA) when waking up and disconnects when going to sleep.

#!/bin/sh
#
# This file should be $HOME/.sleep and $HOME/.wakeup.
# This is run by "SleepWatcher" through /etc/rc.sleep and /etc/rc.wakeup
#
  
# BSD echo command needs this for escape sequences.
test "$SHELLOPTS" && shopt -s xpg_echo
  
tel="tell application"
case $0 in
*sleep)
echo "$tel \"Finder\" to eject \"MUSIC\"" | osascript -
;;
*wakeup)
echo "$tel \"Finder\" to mount volume \"smb://SERENA/MUSIC\"" | osascript -
;;
esac