Sleep Macs via SleepWatcher based on monitor state
Aug 06, '08 07:30:00AM • Contributed by: Anonymous
Aug 06, '08 07:30:00AM • Contributed by: Anonymous
When I use GeekTool, my computer won't go to sleep because my hard drive keeps getting accessed. Since I don't want to let this tool go, I have devised an alternate way to get my Mac to sleep. This remedy uses Bernhard Baehr's SleepWatcher. Now, there has been a hint about using this utility in the past, but it doesn't address a key point: your computer falling asleep when you are using it.
If you are doing a lengthy activity that doesn't involve touching the keyboard or mouse (watching a movie, for instance), your computer should stay awake. SleepWatcher doesn't know that, so in the middle of your movie, your computer falls asleep. The easy way around this is to tell SleepWatcher to sleep only when your monitor is off.
Here is my SleepWatcher config file:
timeout is when you want your computer to fall asleep (in this case, 10 minutes). displaysleep and displaywakeup simply flip a bit in some file that acts as a preference, which I've designated to be /tmp/displayOff.txt. idle looks at the file and determines whether or not the computer should be put to sleep (if display is off, sleep; if display on, don't sleep).
And this is how my SleepWatcher file, in /Library » StartupItems » SleepWatcher, looks:
Now you can use your computer without fear of it falling asleep on you, yet have a secure feeling knowing that it will sleep without your help.
If you are doing a lengthy activity that doesn't involve touching the keyboard or mouse (watching a movie, for instance), your computer should stay awake. SleepWatcher doesn't know that, so in the middle of your movie, your computer falls asleep. The easy way around this is to tell SleepWatcher to sleep only when your monitor is off.
Here is my SleepWatcher config file:
timeout=6000
displaysleep=echo "1" > /tmp/displayOff.txt
displaywakeup=echo "0" > /tmp/displayOff.txt
idle=if [ `cat /tmp/displayOff.txt` -gt 0 ]; then /usr/local/sbin/sleepwatcher -n;fiAnd this is how my SleepWatcher file, in /Library » StartupItems » SleepWatcher, looks:
RunService ()
{
ConsoleMessage "Starting Sleep Watcher"
/usr/local/sbin/sleepwatcher -d -f /path/to/your/config/file
/etc/rc.wakeup
return 0
}
. /etc/rc.common
StartService ()
{
ConsoleMessage "Starting Sleep Watcher"
/usr/local/sbin/sleepwatcher -d -f /path/to/your/config/file
/etc/rc.wakeup
return 0
}
Alternatively, you could put all the preferences from your config file inline with the command execution, but I find it easier to do it like this.
Now you can use your computer without fear of it falling asleep on you, yet have a secure feeling knowing that it will sleep without your help.
•
[15,824 views]
