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

command linemacmacos

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?

Best Answer

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'"
Related Question