Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I want to logout my Mac OS X from the command line. My OS X version is 10.9. I tried command pkill -KILL -u uid, but this command didn't work out. Is there a command that can be used to log out a user from the system using command line only, not AppleScript?

share|improve this question
    
what exactly didn't work out? –  patrix Apr 7 at 13:27
    
on running the command pkill -KILL -u uid the system shows me a grey screen and on waiting for long the system shows the force quit window with no application running –  prateeak ojha Apr 7 at 13:29

2 Answers 2

This has worked for me in the past:

Log out (with confirmation)

osascript -e 'tell app "System Events" to log out'

Log out directly (no confirmation)

osascript -e 'tell app "System Events" to  «event aevtrlgo»'

or

osascript -e 'tell application "loginwindow" to  «event aevtrlgo»'

This way any running application will get noticed and can terminate in a safe fashion.

share|improve this answer
    
osascript -e 'tell app "System Events" to «event aevtrlgo»' showing error: a "<" cant go sfter this to . –  prateeak ojha Apr 7 at 13:34
    
Hmm, works ok for me. Can you try from a shell script instead of the command line, maybe the shell does some strange stuff here. –  patrix Apr 7 at 13:43
    
I'm guessing the OP has some other issue and the normal commands are getting hung up from the comments here and the question description. –  bmike Apr 7 at 16:49

Just kill the loginwindow process.

sudo pkill loginwindow

You could get fancy and specify the user if multiple users have a loginwindow process, but this is an easy one shot, no prompt way to end a user's graphical session.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.