Tuesday, August 25, 2009

Mac OS X tip: activate fast user switching from the keyboard

Warning: if you don't use Mac OS X or fast user switching, feel free to ignore this post.

Still reading? Cool. Time to get my nerd on.

One of the best features of Mac OS X (and other modern operating systems) is the ability to run several graphical sessions concurrently. Fast user switching, as this feature is called in Mac OS X, allows multiple users (say, Hanna and I) to both be logged in and have any number of applications open, and eliminates the need to log out of someone else needs to use the machine. Fast user switching (FUS) gets a lot use at our house, since my iMac currently stores my family's collection of music, photos, and video. Also, while Hanna does most of her work on her laptop, having the extra screen real estate is occasionally useful -- for example, when she was doing the final layout changes to her PhD thesis.

Turning on FUS is simple enough; open System Preferences, choose Accounts, then Login Options, and check the box for "Enable fast user switching". Below this option, you can also choose to have either your short username or just an icon in the menu bar. With FUS enabled, you can then select to login as another user or go back to the login window.

However, there's one problem with this; there's no simple way to do this without using the mouse. There are keyboard shortcuts to logout (Cmd-Shift-Q), or to turn off the display (Ctrl-Shift-Eject), but no way to quickly return to the login screen to allow someone else to use the machine, or simply require a password if you're going away from your desk. This lack of a keyboard shortcut has bothered me for years, but I finally found a way to activate fast user switching from the terminal, thanks to macosxhints.com. This hint, and the discussion around it, provides several ways to activate FUS; some people have it as a shell script, others use third-party utilities to run the command. Since this was something specific to Mac OS X, I decided to create an AppleScript than can then be run from the keyboard using Quicksilver or Spotlight. The script is just line:

do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -suspend"
With this script saved as an application, I can check "keyboard shortcut to go to the login screen" off my wish list for future versions of Mac OS X.

No comments: