Fast User Switching from the command line on a Mac

It seems that some IT departments like to lock out the fast user switching option on company laptops in a lot of companies at the moment. This became a problem for me as I have a local admin account on my work machine, and I have to switch to it whenever I want to install from a dmg file. This got me thinking, is there a command line argument or tool that I could run to do this? Sure enough there is. The only thing you need to look up is the UserId for the user that you want to switch to.

To get the UserId you need to use dscl as follows:

dscl . -read /Users/[username] UniqueID

Then you can use the following command to switch user:

/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID [UniqueID]

For my work machine I have put this command into a shell script within my ~/bin directory. This means that I can quickly switch to my local admin without remembering this command, so I’ve no idea why people would turn of the UI to Fast User switch.

2 thoughts on “Fast User Switching from the command line on a Mac”

  1. This doesn’t work on my Mac running OS X 10.7… the command runs with no errors but does not prompt me for a password (or display any sort of output) and does not switch the current user.

    If it makes any different, I am trying to run it over ssh as I need to switch the user on a remote machine to try to bypass an issue with VNC access…

Leave a Reply

Your email address will not be published. Required fields are marked *