Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,000 hints and counting!

Sleep Macs via SleepWatcher based on monitor state UNIX
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=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;fi
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:
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.
    •    
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[9,929 views]  

Sleep Macs via SleepWatcher based on monitor state | 4 comments | Create New Account
Click here to return to the 'Sleep Macs via SleepWatcher based on monitor state' hint
The following comments are owned by whomever posted them. This site is not responsible for what they say.
Sleep Macs via SleepWatcher based on monitor state
Authored by: processfive on Wed, Aug 6 2008 at 10:39AM PDT
I have a habit of leaving Firefox running with an open Gmail tab, and that seems to prevent sleep from kicking in on my Mac Mini. This seems like a great solution, but I have one concern:

How does this affect things like Time Machine backups or lengthy file transfers? Will SleepWatcher put my Mac to sleep in the middle of a backup, for example?

[ Reply to This | # ]
Sleep Macs via SleepWatcher based on monitor state
Authored by: Balthamos on Wed, Aug 6 2008 at 9:11PM PDT
For lengthy file transfers, this solution will make the computer fall asleep in the middle, and you will probably have to restart the transfer. For Time Machine backups, it will stop those as well, but not to the extent where it would harm your computer/backups. If you want to do something and you don't want your computer falling asleep on you, I suggest you use Caffeine. Just make sure you turn the brightness down on your monitor so you don't have burn in.
Alternatively, you could rework the logic a bit to include a check for a frontmost app (eg if iTunes is frontmost, don't fall asleep). But that may defeat the purpose of this fix. And if you want to check for HDD activity, that's exactly what Apple's standard sleep option does, so you will be stuck back at ground zero (because that's why your computer isn't falling asleep in the first place).

[ Reply to This | # ]
Sleep Macs via SleepWatcher based on monitor state
Authored by: bazzoola on Wed, Aug 6 2008 at 12:52PM PDT
did you just comment out the previous stuff in SleepWatcher StartupItem ? like this?

RunService ()
{
        ConsoleMessage "Starting Sleep Watcher"
#       /usr/local/sbin/sleepwatcher -d -V -s /etc/rc.sleep -w /etc/rc.wakeup
        /usr/local/sbin/sleepwatcher -d -f /etc/sleepconfig
        /etc/rc.wakeup
        return 0
}

. /etc/rc.common

StartService ()
{
        ConsoleMessage "Starting Sleep Watcher"
#       /usr/local/sbin/sleepwatcher -d -V -s /etc/rc.sleep -w /etc/rc.wakeup
        /usr/local/sbin/sleepwatcher -d -f /etc/sleepconfig
        /etc/rc.wakeup
        return 0
}



[ Reply to This | # ]
Sleep Macs via SleepWatcher based on monitor state
Authored by: Balthamos on Wed, Aug 6 2008 at 8:45PM PDT
Yes, you could do it like that; it all depends on what you are using sleepwatcher for. If all you want is the sleep functionality, you can comment out the original commands as you illustrated.

[ Reply to This | # ]