Home » Questions » Computers [ Ask a new question ]

What Is the Mac OS X Terminal Command to Log Out the Current User?

What Is the Mac OS X Terminal Command to Log Out the Current User?

I would like to run something like "sleep 3600; logout", but the logout bash command only closes the current terminal. How do I close the full Mac OS X session?

Asked by: Guest | Views: 64
Total answers/comments: 4
Guest [Entry]

"The following Applescript will logout the current user:

tell application ""System Events"" to log out

You can wrap this up in a bash alias using the osascript command:

alias maclogout=""osascript -e 'tell application \""System Events\"" to log out'""

It is the same as clicking "" > Log out [username]..."", and will logout after a 2 minute wait

This is easily combined with the sleep command:

alias delayedlogout=""sleep 3600; maclogout""

..or could be combined into a single alias:

alias delayedlogout=""sleep 3600; osascript -e 'tell application \""System Events\"" to log out'"""
Guest [Entry]

"I know this is an old question but it helped me, the command I needed on OS X 10.8 is:

ps -Ajc | grep loginwindow | awk '{print $2}' | sudo xargs kill -9

The awk statement is different and the kill -9 ensures the login prompt is shown."
Guest [Entry]

"A nice utility to add to your Terminal is the logout command, to be used like:

logout UserName

Here the how to:

Edit your .bash_profile

nano ~/.bash_profile
Add this line:

logout() {sudo launchctl bootout user/$(id -u ""$1"")}
Save the file pressing ctrl+x
Restart the terminal

You are ready to go ;)"
Guest [Entry]

If you're logged in to a shell as the same user who is logged into the gui of the mac, you could issue a sudo-less command: launchctl reboot logout which does logout the user pretty effectively; it has the caveat of not allowing apps which are being quit from prompting for interaction while quitting, however it does not seem to imply that this is the same thing as killing them outright as a kill (SIG TERM) or kill -9 (SIG KILL) might.