StressFree | David Harrison

Open source development & digital architectural collaboration

SleepWatcher: Mac housekeeping before going to bed

Tags:
Submitted by David on 11 June 2006 - 12:15am
Printer-friendly version
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

WOW!

Dude - I love you. I have the same setup as you pretty much... I have a server with all my music, video and apps on it. Will be trying this on my iBook later today!

don't use samba

its better not to use samba but nfs or afp. samba is odd on macos anyways. nfs and afp is much more reliable and does not need to be remounted after sleeping.

the nslu can do nsf, linux anyway and i think even for windows there is nfs servers

steffen