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

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
macports-dev mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macports-dev

Reply via email to