Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the '10.7: Keyboard Shortcut for Fast User Switching' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.7: Keyboard Shortcut for Fast User Switching
Authored by: oschrenk on Feb 17, '12 07:05:59AM
I had some problems with the script using 10.7.3. a) find-generic-password had problems finding the keychain item b) apple script could paste the password into the security agent password field c) the security agent has no button anymore, so I had to send "return"
--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'/ -switchToUserID `id -ur " & username & "`"

-- Use universal access to enter the text and to click the button
tell application "System Events"
		if (do shell script "stat -f %Su /dev/console") is username then exit repeat
		-- Get the password for the username
			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
			tell application "SecurityAgent" to quit
			do shell script "/System/Library/CoreServices/'Menu Extras'/ -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

[ Reply to This | # ]
10.7: Keyboard Shortcut for Fast User Switching
Authored by: oschrenk on Jun 26, '12 06:28:41AM

There were some users having trouble to set this up. The common mistake was to set the Description field to "User Login". It needs to be the "Kind" field. My error. As I can't seem to edit the answer I posted a public gist to

If there are still problems discussion can be made there.

[ Reply to This | # ]