|
|
#1 |
|
Prospect
Join Date: Jan 2002
Location: Atlanta, Georgia
Posts: 13
|
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 |
|
|
|
|
|
#2 |
|
Prospect
Join Date: Jan 2002
Location: Quezon City, Philippines
Posts: 3
|
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. |
|
|
|
|
|
#3 |
|
Triple-A Player
Join Date: Mar 2006
Posts: 97
|
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.
|
|
|
|
|
|
#4 |
|
All Star
Join Date: Sep 2006
Posts: 860
|
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. |
|
|
|
|
|
#5 |
|
League Commissioner
Join Date: Jan 2005
Posts: 8,475
|
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. |
|
|
|
|
|
#6 | |||||||||||||||||||
|
All Star
Join Date: Sep 2006
Posts: 860
|
This would work just fine but I think what stephenfleming wants to do is run a backup script that may not be done when the scheduler decides to shutdown. Or, he wants to save the most amount of energy possible and wants his computer to shutdown promptly after the backup. |
|||||||||||||||||||
|
|
|
|
|
#7 |
|
League Commissioner
Join Date: Jan 2005
Posts: 8,475
|
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.
|
|
|
|
|
|
#8 | |||||||||||||||||||
|
All Star
Join Date: Sep 2006
Posts: 860
|
That actually seemed to work but when I restarted; the session from the previous shutdown seemed to be active. Also, Camino acted like it had been force quit. Are you sure this works for a clean osx shutdown? |
|||||||||||||||||||
|
|
|
|
|
#9 |
|
League Commissioner
Join Date: Jan 2005
Posts: 8,475
|
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. |
|
|
|
|
|
#10 |
|
Hall of Famer
Join Date: Apr 2002
Posts: 3,315
|
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- |
|
|
|
|
|
#11 |
|
All Star
Join Date: Sep 2006
Posts: 860
|
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.
|
|
|
|
|
|
#12 |
|
Triple-A Player
Join Date: Mar 2006
Posts: 97
|
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. |
|
|
|
|
|
#13 |
|
League Commissioner
Join Date: Jan 2005
Posts: 8,475
|
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 delay 10 tell application "System Events" key down shift key down command keystroke "q" key up shift key up command end tell end idle |
|
|
|
|
|
#14 |
|
All Star
Join Date: Sep 2006
Posts: 860
|
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. Last edited by anika123; 12-19-2007 at 04:46 PM. |
|
|
|
|
|
#15 |
|
Triple-A Player
Join Date: Mar 2006
Posts: 97
|
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?
|
|
|
|
|
|
#16 |
|
League Commissioner
Join Date: Jan 2005
Posts: 8,475
|
Ok, then based on the code from post #9 in this thread, let's do this:
Code:
on idle delay 10 display dialog "About to switch users..." giving up after 10 do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID 502" delay 2 tell application "System Events" keystroke "their password here" delay 1 keystroke return end tell end idle Edit: 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.
Last edited by cwtnospam; 12-19-2007 at 06:48 PM. |
|
|
|
|
|
#17 |
|
Triple-A Player
Join Date: Mar 2006
Posts: 97
|
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.
Last edited by Tuxford; 12-19-2007 at 07:06 PM. |
|
|
|
|
|
#18 |
|
League Commissioner
Join Date: Jan 2005
Posts: 8,475
|
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. |
|
|
|
|
|
#19 |
|
Triple-A Player
Join Date: Mar 2006
Posts: 97
|
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. |
|
|
|
|
|
#20 |
|
League Commissioner
Join Date: Jan 2005
Posts: 8,475
|
Ok, I was able to duplicate the problem. I think this should take care of it:
Code:
on idle delay 10 tell application "Finder" activate display dialog "About to switch users..." giving up after 10 end tell do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID 502" delay 3 tell application "System Events" keystroke "password" delay 1 keystroke return keystroke return end tell end idle |
|
|
|
![]() |
|
|