So I wrote two small shell scripts, called by the login and logout hooks. Because OS X is a multi user OS, you have to consider that more then one user can login and logout. Therefore, the sleep timer must be activated only when the last user loged out of the system.
Here is the login script login.sh:
#!/bin/sh
#
# create login lock
echo $1 > /tmp/login_$1.LOCK
# deactivate system sleep timer
/usr/bin/pmset -a sleep 0
And the logout script logout.sh:
#!/bin/sh
#
# delete own login lock
rm /tmp/login_$1.LOCK
# test other user is logged in
if [ ! -s /tmp/login_*.LOCK ]
then
# no other login lock found, activate system sleep timer
/usr/bin/pmset -a sleep 15
fi
The login script is setting a LOCK file, created with the user name, then it deactivates the sleep timer. The logout script is deleting the user's own LOCK file. Then it tests for other user LOCK files, and when no LOCK files are found, then it activates the sleep timer for 15 minutes. To get the two scripts executed when login/logout occurs, activate them as follow:
sudo defaults write com.apple.loginwindow LoginHook /path/to/script/login.sh
sudo defaults write com.apple.loginwindow LogoutHook /path/to/script/logout.sh
Two simple scripts let you implement a system sleep management.
[robg adds: I haven't tested this one; make sure that the scripts are executable (chmod +x script_name)...]

