Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

SleepWatcher - A utility to run tasks on sleep/wake Pick of the Week
The macosxhints Rating:

[Score: 9 out of 10]
This is the Pick of the Week for the week of August 14th

SleepWatcher has been mentioned here in a number of hints -- it's the best way I've found yet to have actions happen on sleep or wake (or even idle). Note that it's not a GUI application, so you'll want to be comfortable in Terminal before trying to put it to use. But with the ability to have different sleep and wake actions per user, as well as a number of different configuration options, SleepWatcher is a powerful tool for those trying to make their Macs behave in a certain manner on sleep or wake.

I'm not going to say much more about it in this writeup; read the linked hints above for some real-world examples of how you can put it to use. If you want control over the sleep and wake activities on your Mac, SleepWatcher is a great solution.
  • Currently 2.57 / 5
  You rated: 3 / 5 (14 votes cast)

SleepWatcher - A utility to run tasks on sleep/wake | 17 comments | Create New Account
Click here to return to the 'SleepWatcher - A utility to run tasks on sleep/wake' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
SleepWatcher - A utility to run tasks on sleep/wake
Authored by: wgscott on Sep 08, '06 03:27:50PM

I don't know how I missed this but I have been looking for years for something like this. Thanks for posting it.

[ Reply to This | # ]
SleepWatcher - A utility to run tasks on sleep/wake
Authored by: FlyBoy on Sep 08, '06 05:18:55PM

And the developer has always been very responsive. Great little utility! Thanks for selecting this as it deserves recognition.


[ Reply to This | # ]
SleepWatcher - A utility to run tasks on sleep/wake
Authored by: daGrimm on Sep 09, '06 01:26:11AM

"so you'll want to be comfortable in Terminal before trying to put it to use"
Could anyone recommend me a lightweight, easy-to-use introduction to terminal? I do maybe know some very basic commands, but would like to be more comfortable with it. Is there some page or node or anything for noobs to get started? Thanks a lot.

[ Reply to This | # ]
SleepWatcher - A utility to run tasks on sleep/wake
Authored by: FlyBoy on Sep 09, '06 08:42:17AM
Search on Google (or the search engine of your choice) for "bash tutorial." Bash is the shell program that runs by default in Tiger's In very basic terms, consider the "shell program" to be to the Terminal, what the "Finder" is to the Mac. It lets you look at the contents of directories, copy, move and delete files, launch programs, and a whole lot more. Unlike the Finder, the shell operates only with text commands.

Here's an example tutorial on the web for bash:

Hope this helps,


[ Reply to This | # ]
SleepWatcher - A utility to run tasks on sleep/wake
Authored by: wgscott on Sep 09, '06 11:39:18AM
I've actually put together a web page called Unix Links for just this question. I hope it is useful.

[ Reply to This | # ]
Unix FAQ for OS X
Authored by: hayne on Dec 12, '06 12:24:19AM
See this FAQ about using Unix commands on OS X:

[ Reply to This | # ]
SleepWatcher - A utility to run tasks on sleep/wake
Authored by: ADent on Sep 09, '06 09:45:23PM

Does this allow you to do anything useful if your Mac is set to require a password?

(Typ it wakes up for 30-45 sec waiting for a password, then goes back to sleep if no one is there to enter a password).

[ Reply to This | # ]
SleepWatcher - A utility to run tasks on sleep/wake
Authored by: GlowingApple on Sep 10, '06 01:03:36PM

I have mine set to mute my laptop's sound when I put it to sleep. That way if I bring my laptop to a library, class, meeting, etc I don't have to worry about my laptop making any noise when I wake it. Works fine, with a screensaver and password.

~Jayson <>

[ Reply to This | # ]
SleepWatcher - A utility to run tasks on sleep/wake
Authored by: dtrevas on Sep 11, '06 06:10:38AM
If this requires that you know how to use Terminal, why is it better than "pmset?" If you like the Terminal, open it up and type: man pmset and look at all you can do. It really, umm, ticks me off that the Energy Saver/Schedule Preference only allows one pair of wakeorpoweron/(sleep or shutdown) times. After all, it is the official GUI interface with pmset. With pmset, you can do anything you want! I was hoping someone was going to come up with a nice GUI app for this, but I might just have to do it myself, and it won't be pretty!

[ Reply to This | # ]
SleepWatcher - A utility to run tasks on sleep/wake
Authored by: Lliwynd on Nov 16, '08 03:23:26PM

I just went searching for pmset documentation to see if I could get sleepwatcher functionality without a new install.

It seems that pmset and sleepwatcher do different things. pmset is a command-line tool for the energy saver prefs. It allows you to schedule a wake or sleep event. pmset does not seem to allow you to set a specific script or program to run on wake. sleepwatcher adds this capability.

[ Reply to This | # ]
How I use SleepWatcher
Authored by: kahuna on Sep 11, '06 08:42:26AM

I use ncidd as my caller-id log on a linux server. On my PowerBook, I have an ncid client that talks to ncidd and displays name, number and thumbnail image from Address Book when a call is received. However, the client-server connection is broken after a sleep-wake cycle. With SleepWatcher, I restart the ncid client everytime the PowerBook wakes. Maybe not as elegant as fixing the client, but I'm not a programming genius.

[ Reply to This | # ]
Sleep sound on my PowerBook
Authored by: victory on Sep 12, '06 11:45:08AM
I use SleepWatcher to play a sound every time my PowerBook goes to sleep. In particular, my .sleep script basically invokes a cmd-line sound player app* such as found here or here. (Experienced AppleScripters could probably do some similar magic with osascript or something.) The sound I have the PowerBook play comes from here.

Yes, it's silly. Yes, it's stupid, but besides making me laugh, it actually does has a practical effect -- it tells me that the PB has shut down successfully before I tuck it away in a carrying case and begin hefting it around. In the past, I've run into a sporadic problem of the PB not sleeping properly when I closed the lid. This created a problem with trapped heat and increased the risk of toting around a unit that I thought was safely asleep that wasn't.


* BTW, if you are a user of the excellent TextMate text-editor from, there's an (apparently) undocumented cmd-line sound app already tucked away inside it. Hint: TextMate/

[ Reply to This | # ]

Automatically establish internetconnections via the Cisco VPNClient on start- and wake-up
Authored by: Sito on Oct 20, '06 07:56:35AM
I was annoyed by always being forced to reestablish the Internetconnection by the Cisco-GUI after waking up my machine. Now, by the help of SleepWatcher (btw: thanx for the great hint and thanx for the software) the connection is always being reestablished automatically w no need of using the GUI anymore. Here is, what I did:

1. Installed the Files "SleepWatcher" and "SleepWatcher StartupItem" from the downloaded SleepWatcher File.

2. Wrote a little script (I used Textedit) containing just the following two lines:

vpnclient connect PROFILE
(whereas PROFILE has to be replaced by the Name of the File your Cisco VPNClient works with located in …/private/etc/opt/cisco-vpnclient/Profiles/ – btw the path is invisible but can be made visible with e.g. MacExplorer)

3. Saved the such created Texteditfile as ".wakeup" (w/o anything written before the stopmark and w/o the quotes) in my Homedirectory where it is being placed as an invisible file (but with e.g. MacExplorer easily to find if you need to edit it).

4. Opened the Terminal and made the ".wakeup"-file an executable Unix-file by typing the following line:

chmod +x /Users/MYNAME/.wakeup

(whereas MYNAME has to be replaced by the name of your Homedirectory).

5. Restarted my machine.

And that did it. Now, whenever I startup my machine or wake it up, the internetconnection is automatically being (re)established. Another advantage: You won´t need the Cisco-GUI anymore and therefore will have a bit more space in your dock for something else ;-)

[ Reply to This | # ]

Automatically establish internetconnections via the Cisco VPNClient on start- and wake-up
Authored by: Sito on Oct 20, '06 08:48:33AM
Forgot one thing to mention: This hint only works if there is no prompt for your password on login to the Cisco-Network. To get rid of the prompt, there will be some editing necessary on the Connection-Profile placed in the folder …/private/etc/opt/cisco-vpnclient/Profiles/ (you can browse hidden folders with e.g. MacExplorer):

1. Shut down the VPN-Connection and quit the GUI (because it will override all of the following, when being closed later).

2. Open the YourProfile.pcf in e.g. Textedit (whereas "YourProfile" is the Profilename the Cisco-GUI shows when connecting).

3. Find the line Username= and make sure that your Username as distributed by your admin is entered there.

4. Find the line SaveUserPassword. If the value is set to =1 and your username (step 3) was already entered, everything is fine and you can use the former posted hint. But if the value is set to =0, set the value to =1 and go on with the following steps.

5. Now, find the line UserPassword and behind the = type in your personal userpassword you got from the admin.

6. Close Textedit and browse to the file (YourProfile.pcf (see above)) in the folder named above (again with e.g. MacExplorer).

7. Select the pcf-file you just edited and press command-i to get the file information.

8. Make sure the item "locked" is being highlighted. This way your editing won´t be lost after using the Cisco-GUI at a later time.

Now, the former posted hint should work. To make sure, that your editing was fine you might want to use the Cisco-GUI to see if you got rid of the prompt for your account and your password.

[ Reply to This | # ]

Enable/disable Energy Saver's disk sleep
Authored by: mattmoss on Oct 14, '08 01:21:00PM
I found that an external FW800 hard drive I have (used only for Time Machine) was being put to sleep by the OS, only to be awoken 5 minutes later by the OS. The hard drive is usually quiet except when it spins up, and this periodic noise was rather annoying (and I don't imagine is all that good for the disk either, to be spun down and back up every 10 minutes).

Turning off Energy Saver's control of disk sleep (via System Prefs) didn't help... It worked great while using the iMac, but for some reason when I put the machine to sleep, it would wake up within 10 minutes, presumably because the drive was no longer being put to sleep. (Don't know why that should happen, but it does.)

I tried tinkering with the disksleep parameter of pmset, to change the interval, but with no better results.

Now, I have modified the rc.sleep and rc.awaken scripts from SleepWatcher to run pmset -c disksleep 10 (rc.sleep) and pmset -c disksleep 0 (rc.awaken). Everything seems happy!

[ Reply to This | # ]

I finally got Sleepwatcher to work
Authored by: tomhayes on Dec 16, '09 02:49:05PM

I recently purchased a SmartStrip power outlet for my computer setup to turn off devices when the computer went to sleep.

It worked - except for my Hitachi Simpletech 2GB drive. The external drive has a "power on auto" feature where you plug it into the wall and then into to the computer and only when both the wall outlet and the computer are on does the drive come on.

When the computer went to sleep the Powerstrip would turn off power to the hard drive and the USB port on the Mac would sense that the drive was removed and it would trigger some sort of event where the computer would immediately wake from sleep and I'd get a Device Removal Warning.

I then plugged the external drive into one of the "Always Powered" outlets, but it had the same issue.

I downloaded SleepWatcher ( and installed SleepWatcher and the Sleepwatcher start-up items program.

I created a file in my home directory as named .sleep and chmod r+x it. (note this thread kept talking about Desktop/.sleep , it should be in your home directory which is commonly refereed to as "~" or something like /bootdrive/usr/yourusername)

.Sleep contained the following command:
osascript -e 'tell application "Finder" to eject "2TB"'

Where 2TB was the name of my external drive.

When the computer went to sleep Sleepwatcher started and finder started to eject the drive and the computer went to sleep. The drive did not completely unmount before the computer went to sleep and it triggered some event that would wake up the Mac. The external drive would turn on and mount again with the Device Removal Warning effectively stopping sleep.

So I modified .sleep to contain:
osascript -e 'tell application "Finder" to eject "2TB"'
osascript -e 'tell application "Finder" to delay 10'

Now the drive unmounts, finder waits 10 seconds and then the computer sleeps. It works like a charm.

I created a file called .wakeup that contains:
backupsVolume=`diskutil list | awk '/ 2TB / {print $6}'`
if [ ! -z "$backupsVolume" ]
diskutil mount $backupsVolume

This mounts the drive when the computer wakes from sleep.

Thank you to Sleepwatcher, this thread, and ( for helping me with this.

P.S. I am running this on a Mac pro with Snow Leopard.

[ Reply to This | # ]
SleepWatcher - A utility to run tasks on sleep/wake
Authored by: radek on Apr 20, '10 01:16:25AM
If you are a fink user, just type
    fink install sleepwatcher
in Terminal and you're done

[ Reply to This | # ]