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: mkuron on Jun 07, '10 08:15:33AM
To do this, save the following as a file named com.yourname.backgroundUserLogout.plist in the

LauchAgents folder of each user's Library folder

You should be able to just place it in the root-level LaunchAgents folder (/Library/LaunchAgents). LaunchAgents always get run inside a user's session, upon login (in contrast, root-level LaunchDaemons by default run in the loginwindow context).

I haven't tested this specificially for your hint, but in my other work with LaunchAgents, I haven't noticed any difference between it being placed in the user-level LaunchAgents folder and the all-users LaunchAgents folder.



[ Reply to This | # ]
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 | # ]
Log out background users after time limit
Authored by: Fairly on Jun 13, '10 01:57:33PM

Yes, but then it's not user-specific, and he specifically wanted to make it user-specific.



[ Reply to This | # ]
Log out background users after time limit
Authored by: horhey23 on Nov 21, '10 05:25:09PM

What would one name the plist file if using your suggestion to set this up for all users in the root folder? Just remove the "username" part?



[ Reply to This | # ]