Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Setting idle perameters per user' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Setting idle perameters per user
Authored by: magnamous on Aug 15, '08 05:52:52PM

I managed to get this working, so I thought I'd share. I did this with SleepWatcher 2.0.5 installed:

  1. Using your favorite text editor as root, open
     /Library/StartupItems/SleepWatcher/SleepWatcher
    Modify this:
    
    StartService ()
    {
            ConsoleMessage "Starting Sleep Watcher"
            /usr/local/sbin/sleepwatcher -d -V -s /etc/rc.sleep -w /etc/rc.wakeup
            /etc/rc.wakeup
            return 0
    }
    
    so that it looks like this:
    
    StartService ()
    {
            ConsoleMessage "Starting Sleep Watcher"
            /usr/local/sbin/sleepwatcher -d -V -s /etc/rc.sleep -w /etc/rc.wakeup -t 18000 -i /etc/rc.idle
            /etc/rc.wakeup
            return 0
    }
    
    The only line that changes is /usr/local/...
    I used 18000 because I wanted it to do something after 30 minutes of idleness.

  2. Now type this in the Terminal as root:
    
    cp /etc/rc.sleep /etc/rc.idle
    
    and as before, open rc.idle in your text editor of choice. In there, change this:
    
    for user in `echo 'show State:/Users/ConsoleUser' | scutil | awk '/kCGSSessionUserNameKey/ { print $3 }'`; do
            home=`eval echo ~$user`
            if [ -x "$home/.sleep" ]; then
                    logger -t $0 "executing .sleep of user $user"
                    su - $user -c "$home/.sleep"
            fi
    done
    
    so that it looks like this:
    
    for user in `echo 'show State:/Users/ConsoleUser' | scutil | awk '/kCGSSessionUserNameKey/ { print $3 }'`; do
            home=`eval echo ~$user`
            if [ -x "$home/.idle" ]; then
                    logger -t $0 "executing .idle of user $user"
                    su - $user -c "$home/.idle"
            fi
    done
    
    In other words, replace all instances of .sleep with .idle.

  3. Now, in your home folder, create a new text file called .idle, and add whatever you want it to do when it's idle. (I added a line to tell it to fast-user-switch to the login screen.) Once you've saved your changes, remember to make the file executable by typing chmod +x .idle.

When I first created this, I wanted to test it to make sure that it worked, so I set -t in the first step to 10 instead of 18000 because I was impatient. Do not be impatient. If you want to test this to make sure it works, make -t at least 100 or 200 (10 or 20 seconds) to give yourself some breathing room for changing it back once you've discovered that it works.

The nice part about this implementation is that each user can specify what to do at idle time, instead of one implementation to rule them all (so to speak). Even nicer would be if each user could specify what he wants the delay to be before the .idle script kicks in. However, I have no idea how to implement that. Perhaps by using the --config option...? If someone knows how, by all means, please reply.

[ Reply to This | # ]