Home / Tutorials / Mac Tips: Keyboard Shortcut for Fast User Switching

Mac Tips: Keyboard Shortcut for Fast User Switching

I have been using this hint until it broke in Lion. (See the last comment in that hint.)

Macbook-Keyboard-Shortcut
After not being able to find a complete solution, I came up with this:
*Please note that this is not a secure solution. Your account password is stored in plain text, just as in the original hint.*
There is a way to collect the password from the keychain (see the above link and read through the comments), but I don’t quite understand that just yet.
Also, this comes with the usual use at your own risk and I am not responsible if your computer explodes warnings.

  • Open Automator
  • Select Application
  • In the left column select Utilities
  • In the centre column drag Run AppleScript to the area on the right
  • Copy and Paste this code, changing USERNAME and PASSWORD accordingly:
on run {input, parameters}
  set theUser to "USERNAME"
    set theUser to do shell script "/usr/bin/id -u " & theUser
    do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID " & theUser
    tell application "System Events"
      set token to "1"
      repeat while token = "1"
        if exists process "SecurityAgent" then
          delay 1
          keystroke "PASSWORD"
          keystroke return
          set token to "0"
        end if
      end repeat
    end tell
    return input
  end run
  
  • Go to the File menu and select Save…
  • Make sure the File Format is Application
  • Type in the name you select where you wish to save the App.
  • Assign a keyboard short cut in your favourite launcher App. In my case, I have assigned Control+Option+a with Quicksilver.

This does work, but pay attention to the caveat about storing the plain text password. If you extend this to get the password from the Keychain please post your addition in the comments.

Download Full Version

About J8mesz

I don't strive to be #1, but to be the only one.

Leave a Reply