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


Click here to return to the 'Log out background users after time limit' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Log out background users after time limit
Authored by: Sesquipedalian on Jun 07, '10 08:22:13AM

Absolutely true. But I needed different settings for different users, so I had to do it this way instead.



[ Reply to This | # ]
Log out background users after time limit
Authored by: mkuron on Jun 07, '10 08:35:21AM

Ok. Still I think it's worth mentioning: having a global LaunchAgent would probably be very useful for people managing Macs with large numbers of (network) users so that copying one to every individual user's folder would simply be impractical. In such a scenario, you could still individualize the script based on group membership - e.g. if you want to have individual logout times:

if [ $(id $UID | grep "80(admin)") = "" ]; then logouttime=60; else logouttime=1440; fi;

Adding this to the beginning of your third ProgramArguments string and replacing $(( 60 * 30 )) with $logouttime would give you a 1-hour logout wait time for non-admins and a 24-hour wait time for admin users.



[ Reply to This | # ]
Log out background users after time limit
Authored by: Sesquipedalian on Jun 07, '10 08:55:30AM

Very nice!

(Although you'd want to use 3600 and 86400 instead of 60 and 1440.)

Edited on Jun 07, '10 09:01:50AM by Sesquipedalian



[ Reply to This | # ]
Log out background users after time limit
Authored by: Azur Logix on Aug 30, '10 03:24:06PM

I put this in /Library/LaunchAgents but I'm guessing I must not have properly integrated your code into the above hints code.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.global.backgroundUserLogout</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>-c</string>
<string>if [ $(id $UID | grep "80(admin)") = "" ]; then logouttime=60; else logouttime=1440; fi; if [ $(stat -f %u /dev/console) == $UID ]; then if [ -e /tmp/backgroundUserLogout.$UID ]; then rm /tmp/backgroundUserLogout.$UID; fi; elif [ ! -e /tmp/backgroundUserLogout.$UID ]; then touch /tmp/backgroundUserLogout.$UID; elif [ $(( <code>date +%s</code> - <code>stat -f %m /tmp/backgroundUserLogout.$UID || printf 0</code> )) -ge $logouttime ]; then rm /tmp/backgroundUserLogout.$UID; osascript -e ‘tell application “System Events” to log out’; fi</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StartInterval</key>
<integer>60</integer>
</dict>
</plist>



[ Reply to This | # ]