Shared access to Mac OS X: how to manage wakeonlan and sleep

Raphael Straub raphael at ira.uka.de
Tue Jul 7 01:20:16 PDT 2009


Jean-Michel Pouré wrote:
> * How can I manage sleep so that it is triggered after an SSH
> disconnection and let's say 30 minutes of inactivity.
>
> * When using screen, I would like to be sure that the Mac does not  
> go to
> sleep.

I had the same problem. My solution is to turn off idle sleep and use  
the following sleep script:


#!/bin/bash

#how many checks are necessary to shutdown
checks=$1

#time between checks (see man sleep)
time=$2

### main loop
count=0
while :
do
        if [ `who | wc -l` -eq 0 ]; then
                count=`expr $count + 1`
        else
                count=0;
        fi
        if [ $count -eq $checks ]; then
                count=0;
                pmset sleepnow
        fi
        sleep $time
done


I start this script by the following launchd plist in /Library/ 
LaunchDaemons:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd 
">
<plist version="1.0">
<dict>
	<key>GroupName</key>
	<string>nobody</string>
	<key>Label</key>
	<string>de.uni-karlsruhe.ibds.auto_sleep</string>
	<key>OnDemand</key>
	<false/>
	<key>ProgramArguments</key>
	<array>
		<string>/usr/local/sbin/auto_sleep.sh</string>
		<string>12</string>
		<string>300</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
	<key>UserName</key>
	<string>root</string>
</dict>
</plist>


As you can see, the script checks every 300 seconds if somebody is  
logged in and if this test fails 12 times in succession, the computer  
is put to sleep.

Regards,
	Raphael

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4445 bytes
Desc: not available
URL: <http://lists.macosforge.org/pipermail/macports-dev/attachments/20090707/6fb5cb5e/attachment.bin>


More information about the macports-dev mailing list