Tiny Deathstars of Foulness

Fast User Switching allows a user of Mac OS X to switch accounts without logging out of the account they are currently in. There are a number of uses for this, from troubleshooting to managing workflow. The back end functionality comes from the CGSession binary located in /System/Library/CoreServices/Menu Extras/ There are a couple of options you can use with CGSession, -switchToUserID and -suspend.
/System/Library/CoreServices/Menu Extras/ -switchToUserID 1022
If an account has no password then the switch should occur automatically. If there is  password then you can simply bring up a login window using the following command (you can also switch to a given user id but it will ask you for a password):
/System/Library/CoreServices/Menu Extras/ -suspend
You can also invoke CGSession from other languages. AppleScript seems to be a common one that we use. To do so you might use the following line in AppleScript to bring up the fast user switch screen via AppleScript:
do shell script ” /System/Library/CoreServices/Menu Extras/ -suspend”
You could also use the following to switch to a known user en masse (rather than a UID), such as localadmin here:
set userid to do shell script “id -u localadmin” do shell script “/System/Library/CoreServices/’Menu Extras’/ -switchToUserID ” & userid
If you would also like to add a password as a part of the AppleScript then you would tell “System Events” to tell a window of SecurityAgent to set the value of the password text field to the password you would like to use. You could then loop that through every option in a dictionary of possible password combinations if you aren’t then sure what that password should be… Random sidenote: In that resources directory, there are some image files. I have changed my /System/Library/CoreServices/Menu Extras/ file to be a different icon, allowing me to have a little custom image. It’s the little things…

May 3rd, 2010

Posted In: Mac OS X, Mass Deployment

Tags: , , , , ,