If you’re like me, you’re always sweating when you take your MacBook from your bag during a lecture and open it up: “Did I mute the sound before I put it to sleep?”. I’m not really good at predicting when I’ll be using my Mac again, so I tend to forget.
However, the world doesn’t stop when you put your Mac to sleep. With each minute that passes, the probability of new email having arrived or iCal events being due increases. These things all have their own notifications and those more often than not involve sound. Nice when you’re not paying attention; not so nice when you don’t want everyone else’s attention pointed towards you after your MacBook loudly announces to everyone that the class you’re in was due five minutes ago.
Wouldn’t it be nice if you could be sure that your Mac always awakes quietly? It’s actually not that hard to do ‘unix style’. All you need is a tool called SleepWatcher, written by Bernhard Baehr and one line of script.
HOWTO: Mute system volume on sleep
- Download and install SleepWatcher. You’ll want to install sleepwatcher itself first and then the StartupItem. This last one not only ensures that sleepwatcher is run on startup, but also creates default rc.sleep and rc.wakeup scripts and sets up sleepwatcher to use those.
- Add a mute command to the sleep hook. Depending on whether you want this to work for all users or just yourself, open /etc/rc.sleep or create a file called .sleep in your home directory ad put these lines at the top (/etc/rc.sleep already starts with the shebang line, so you can skip it):
#!/bin/sh osascript -e "set volume with output muted"
This simple script uses a utility called “osascript” to execute a line of AppleScript that mutes the system volume, just like pressing the “mute” key on your keyboard would do (but it doesn’t unmute if the system was already muted).
If you’re putting this in ~/.sleep, don’t forget to make the file executable by typing “chmod a+x ~/.sleep” in Terminal.
Note that you could also put these commands in one of the wakeup scripts, but they might not get executed in time to prevent notification sounds on wakeup.
That’s all! Now every time you put your Mac to sleep, you’ll know you are safe from those awkward moments ;)