![]() |
Automatic Logout
I'm trying to craft a Unix command line that I can add to crontab to execute a graceful Log Out of the Macintosh environment. Basically, I want to be able to walk away from my machine at night (running a backup or something), but be sure that everything gets tidied up and is ready for me to login the next morning.
This should be incredibly simple. I can't figure out how to do it either in AppleScript or from the command line. Any suggestions? Thanks! Stephen Fleming |
Off the top of my head I'd use kill, but that isn't necessarily gracious. If the application gets a SIGTERM or SIGQUIT, it should try to quit gracefully.
With regards to an AppleScript doing a QUIT, the issue I can think of is applications that ask for a "confirmation" when quitting, such as browsers asking for a confirmation while downloads are in progress, or documents that need saving. The Finder logout eventually times out when no response is given. |
Has this issue been solved in recent OSX releases? Set my server to login as public user. I manually login as an admin user. Want to ensure that when I walk away, the admin user will eventually automatically logout.
|
I am no expert but you should be able to write in your scripts to modify a certain file, say a text file or something. Then set up launchd to monitor this file for changes. When it detects a change it will call the applescipt you have written that uses "system events" to logout or shutdown or whatever you want. So long as it is in the system events dictionary.
This could all be done (the backup and stuff) from a single applescript. |
If you're going to walk away, and you want it to log out, why not schedule it to shutdown in the Energy Saver preference pane?
If you want to walk away leaving the computer running but require a password to get back in, then set your screen saver to require one. While you're at it, make your screen saver something useful like folding@home. |
Quote:
|
Well, if he wants it to shutdown, the Terminal command is:
shutdown -h now Simply logging out is another story, in which case I think it would be much more productive to use a distributed computing screen saver and set it to require a password. ;) |
Quote:
|
The man page is dated December 11, 1998 so developers should be aware of it. I did see the same problem with Camino though.
Of course, if you're going to put this in a script, it would be best to close all applications before using the command. Oh, just in case some one has a legitimate need to logout instead of shutdown — although I can't think of one — the command key for logout is command-shift-Q. If you want it to take affect immediately, it's command-option-shift-Q. That should be easy enough to GUI script in Applescript. |
I don't remember the syntax offhand, but in AppleScript there is something like:
shutdown without saving [I forget exactly... but it is slightly more "graceful".] -HI- |
Wow, was this thread really started in 2002? I doubt stephenfleming even cares anymore. But the info is still good for newcomers and interested parties.
|
Since the machine is server, I want it always running. Since it runs some server applications, I have it login automatically as a standard user.
To get to my private shared folders, I login as a second user sometimes, and then walk away. I want this second user to automatically logout after a period of time. Can someone consolidate these ideas into a strategy for me? Thanks. |
You could save this as a stay open application and put it in your startup items. After about 10 seconds of inactivity, the 2:00 minute warning for logout will popup. You can cancel the logout if you're there, and it will popup after the next inactive period.
Code:
on idle |
I think what you want is a logout script. This is way beyond my means but this might be a relevant link http://managingosx.wordpress.com/200...aunchd-gotcha/. Anyway a logout hook is apparently what you need. I would hope that applescript could do this. Where is tw when you need him. Anyone one else with logout hook experience?
The solution by cwtnospam looks like a good solution as well. |
Great. Got the script working. Would be nice if I could also then automatically log back into the other standard user. This script just gets me to the login name screen. The other user is typically running in the background anyway. I wonder if it's energy saver settings would kick in and dim the screen at this login window?
|
Ok, then based on the code from post #9 in this thread, let's do this:
Code:
on idleEdit: Note that providing the password in the script isn't secure. Since it's a standard account and you auto login anyway, it shouldn't be a huge problem. ;) |
This script gets stuck after the password entry, on Return. Ends up looping back at the About to switch warning. Need to click the login button. Also wonder if need to disable this script when user is in the background after switching.
|
Two things that could cause that problem:
1) The user id isn't correct. 2) The password isn't correct. I don't think the script needs to be disabled when in the background. When I tried it everything seemed ok. |
After the script runs and gets stuck in the loop, I simply click the login button, and it switches user. So the user id and password are correct.
Seems to switch to the Finder (or maybe to the looped script) before the Return is recognized. |
Ok, I was able to duplicate the problem. I think this should take care of it:
Code:
on idle |
| All times are GMT -5. The time now is 05:42 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.