Logout from OS X via the Terminal

Feb 21, '05 08:17:00AM

Contributed by: sbfaulkner

When I'm primarily using the keyboard, I find it a bit annoying to have to switch to the mouse for anything (even if just to logout). Normally, if you type logout in your Terminal window, your shell quits, but of course, you're still logged in to OS X. Add the following shell function to your .bashrc (or .bash_profile, or wherever else depending on your setup), and voila -- you really do log out...

logout() {
  osascript -e 'tell application "System Events" to log out'
  builtin logout
}
[robg adds: Depending on the state of your windows, you'll probably have to dismiss some dialog boxes in order to complete the logout, but this can be done using the keyboard as well. I'm not sure I'd replace the built-in logout function, as I've become quite used to using it to just logout from the Terminal. Instead, you might want to change the command's name to logout2, or something else, in order to prevent an accidental total logout.]

Comments (14)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20050216114450735