I need to create a script that will auto log out a user. This will be used with a hidden admin account (via the HiddenUsersList:
http://support.apple.com/kb/HT5017) so if a user logs in to this account it will automatically log them out.
Any ideas? Thanks!
I don't quite understand what you mean by "auto log out".
Does this happen immediately? That is, is an attempt to login immediately met with a logout?
Or does it happen after a time interval? That is, is a login accepted, but a logout is then forced after a time period, such as 5 minutes.
If you want immediate logout, then the simplest is to change the account to the equivalent of "Sharing only" using System Preferences > Accounts.
Try this:
1. Open System Preferences > Accounts.
2. Unlock.
3. Control-click (right-click, secondary-click) on the account you want to change.
4. Observe a contextual menu "Advanced Options..." appears.
5. Choose it.
6. Observe a sheet drops down with settings for the user.
7. Change Login shell to
/usr/bin/false
8. Change Home directory to
/dev/null
9. Click OK.
The settings in 6-7 are what a "Sharing only" account receives by default.
I recommend testing this on an account created expressly for testing. Only after it's been proven to behave correctly should it be applied to the desired target account. Testing includes at least:
- trying to login as the user,
- trying to share as the user,
- and trying to do a fast user switch to the user.
The above description may differ somewhat from what you see. You didn't identify your OS version, so I described how it works in 10.6 Snow Leopard.
I don't see much purpose in having an admin acct that can't be logged in, so maybe you can describe what you're trying to achieve with it.