How do you create a keyboard shortcut that activates fast user switching (i.e. brings up the login window) in Mac OS X Snow Leopard?
I'm trying to emulate the Windows Start+L keyboard combination, which I miss from my time using Windows.
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
For 10.6 Snow Leopard, one can easily add a Service using Automator, and then assign any keyboard shortcut using System Preferences. See Fast User Switching/Apple Menu? for details.
If you are at the CLI, you could have the following alias set to switch quickly:
alias switch='/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend'
I use BetterTouchTool for a lot more than just this but, one of the actions it allows you to do is "Show the Login Screen" (which is different from logging out and leaving you at the login screen). I use it ALL THE TIME to lock my machine when I leave it for extended periods of time… Here's a screenshot:
Strictly speaking, Command+Option+Q will log you out (with "Are you sure" prompt).
But I don't see any way to trigger a fast user switch via keyboard. Now you could write an AppleScript script, which you could associate with a keystroke. For example, see this for implementation details.
set thePassword to "password" set N to name of (info for (path to me)) set AppleScript's text item delimiters to (".") set N to first text item of N set AppleScript's text item delimiters to "" set N to do shell script "/usr/bin/id -u " & N do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID " & N tell application "System Events" tell process "SecurityAgent" to set value of text field 1 of group 1 of window 1 to thePassword click button 2 of window 1 of application process "SecurityAgent" end tell
According to Király in Apple Support Discussions, he says this combination works:
...This can be done with Automator and Spark:
Open Automator, select Run Shell Script, and paste in this (all on one line):
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend
File -> Save As... -> select "Save as application" and save the app in a convenient spot. Then use Spark to assign a keyboard shortcut to open that app.
I use Automator and Spark to switch to the login window and then put my Mac to sleep when I press control-F13...
About Spark 3.0b9 software:
Spark is a powerful, and easy Shortcuts manager. With Spark you can create Hot Keys to launch applications and documents, execute AppleScript, command iTunes, and more... You can also export and import your Hot Keys library, or save it in HTML format to print it. Spark is free, so use it without moderation!
A slightly different way of doing this, with added security benefits (or annoyances depending on your view-point), is to
To do this, you need to adjust the following settings in your System Preferences application:
Exposé & Spaces, in the
Exposétab, set one of your
Active Screen Cornersto
Start Screen Saver.
Generaltab, check the option of
Require password ... after sleep or screen saver begins(you may want to choose
immediatelyfrom the drop-down).
You'll have to do the latter on each account (unfortunately there's no global setting for this).
Then you can move your mouse to the appropriate corner of the screen to lock the computer (by starting the screen saver). When someone presses a key/moves the mouse they'll be prompted to log in and can switch users from there.
If the desire is to lock (like Window-L in Windows), then there's a very simple solution .. set your screensaver to lock the screen (require logon) and use ctrl-shift-eject (bottom left two keys + top most right key). This locks your screen.
To switch to a specific user I invoke a script I found in the comments of a hints.macworld.com article. I had problems with it so I tweaked it to get if to work. The password is stored in the keychain, so you don't have to worry about storing login password in cleartext. You can find the gist here.
--This script MUST be named "Switch to User.scpt", where User is the name of the user to switch to. --You must first make a password item (a.k.a. a key) for the other user's password using Keychain Access, and call it "", where "user" is the other user's name and with the description "User Login". The script assumes that you make this key in your login.keychain, which is the default one. --The first time you run this script, you will be prompted to allow Keychain Scripting to access the password of the key. --This script requires "Enable access for assistive devices" to be enabled in the Universal Access system preference pane. set username to word -1 of my findReplace(".scpt", "", (path to me as text)) -- Invoke Fast User Switching. The `id -ur username` part gets the uid number that corresponds to the username and substitutes it at the end of the CGSession command do shell script "/System/Library/CoreServices/'Menu Extras'/User.menu/Contents/Resources/CGSession -switchToUserID `id -ur " & username & "`" -- Use universal access to enter the text and to click the button tell application "System Events" repeat if (do shell script "stat -f %Su /dev/console") is username then exit repeat -- Get the password for the username try set pswd to (do shell script "security find-generic-password -g -s \"" & username & "\" -D \"User Login\" 2>&1 1>/dev/null | sed -e 's/password: \"//' -e 's/\"//'") on error exit repeat end try if exists window 1 of application process "SecurityAgent" then tell process "SecurityAgent" to set value of text field 1 of window 1 to pswd key code 36 exit repeat else tell application "SecurityAgent" to quit do shell script "/System/Library/CoreServices/'Menu Extras'/User.menu/Contents/Resources/CGSession -switchToUserID `id -ur " & username & "`" end if end repeat end tell on findReplace(findText, replaceText, sourceText) set ASTID to AppleScript's text item delimiters set AppleScript's text item delimiters to findText set sourceText to text items of sourceText set AppleScript's text item delimiters to replaceText set sourceText to sourceText as text set AppleScript's text item delimiters to ASTID return sourceText end findReplace
To just invoke the Login Screen I have another script. You can find the gist here
do shell script "'/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession' -suspend"
Both scripts are in my quicksilver catalog. Switching between user accounts is a matter of a few seconds.