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


Click here to return to the '10.3: Use fast user switching via AppleScipt and Keyboard Shortcuts' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.3: Use fast user switching via AppleScipt and Keyboard Shortcuts
Authored by: Frederico on Nov 07, '03 11:25:54PM
I'm giggling each time I use this:

(* Fast User Logout Access v.1.0 by Frederico; frederico@mac.com *)
(* Inspired by Rob Griffiths and 'makaio' of MacOSXHints.com; 7 November 2003 *)
(* Feel free to modify as required. Distribute with appropriate credits, please.*)
(* Compile this script as an application, or save it as a script and place in your Scripts Menu for fast access. *)
(* Even better, use a keyboard input shortcuts utility, such as Youpi Key or Keyboard Maestro to enable keystroke access;
  I used 'Command-Option-Shift-Q' to complement the standard 'Log out...' (Command-Shift-Q). *)

global a, b, c, d, e, f, g, h
set a to "Switch User"
set b to "Just Lock Screen Now"
set c to "cancel"
set d to "Change this script text to the most frequently accessed user or other text"
set e to "Enter short name of user to switch to:"
set f to ""
(* If you just want a fast screen-lock function, change g to '2' *)
set g to 3
set h to do shell script "whoami"
my getNewUser()
on getNewUser()
	(* following text on one line! *)
	set {userName, buttonChoice} to {text returned, button returned} of (display dialog f & e default answer d buttons {c, b, a} default button g with icon 2)
	(* preceeding text on one line! *)
	if buttonChoice is a then
		if userName is d then
			set f to "No Such User!!"
			set d to "  Enter Valid user shortname here."
			my getNewUser()
		else if userName is h then
			set f to userName & " is already logged in! "
			my getNewUser()
		else
			try
				set newUser to do shell script "id -u " & userName
			on error errMSG
				log errMSG
				set f to errMSG
				my getNewUser()
			end try
		end if
		try
			(* be sure there are TWO backslash characters after the word 'Menu' in the next script line!! *)
			(* following text on one line! *)
			do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID " & newUser
			(* preceeding text on one line! *)
		end try
	else if buttonChoice is b then
		(* be sure there are TWO backslash characters after the word 'Menu' in the next script line!! *)
		(* following text on one line! *)
		do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -suspend"
		(* preceeding text on one line! *)
	else if buttonChoice is c then
		(* do other stuff here if you want *)
	end if
end getNewUser
Enjoy! Frederico

[ Reply to This | # ]
10.3: Use fast user switching via AppleScipt and Keyboard Shortcuts
Authored by: maartensneep on Nov 08, '03 08:31:38AM

I like my script better ;)

It presents you with a list choice dialog. First item is "Login Screen", which switches you to the login screen. The rest of the items in the dialog are the long user names (of the real users, not the "nobody" pseudo user. For good measure the root user is removed from the list (most people don't have it activated anyway) and the current user isn't in the list either.

You can download the source of the script from http://www.nat.vu.nl/~sneep/ars/FUS.applescript

Hope this helps,
Maarten.



[ Reply to This | # ]
10.3: Use fast user switching via AppleScipt and Keyboard Shortcuts
Authored by: Frederico on Nov 08, '03 06:42:33PM

Not bad; I'm sure some people will forget who they are and need a list of choices. (;

Seriously, though; I had done one version with a list of users in an attempt to follow the current model, but coming from a lab environment where an extra measure of security is had by not presenting a list of eligible user names, not to mention the lack of fun in scrolling through a long user list, I prefer the blank text login screen.

The real problem I had with yours is that it suffers from taking too long to generate a dynamic list of users when there are more than two or three users present. Your script, attached to Keyboard Maestro, takes nearly three seconds to run and present the login screen with five users, and the better part of half a minute on a machine with more than 40 users, whereas my script pops up almost instantaneously in either case.

I don't need to tell you that the entire point of 'Fast User Switching' is lost with your method. (:

I didn't spend much time on my user list routine, nor did I on yours, but its obvious that your repeat routine is the Achilles Heel. You've got three shell calls for each user. Tedious. You could greatly accelerate it by reformatting the shell calls into a single line for each user, but, you still have a problem with anything more than a typical family computer with five or so accounts, IMHO.

Just a hint: You can get a list of all current user short names and long names much quicker than you have by reading a certain .plist.

Still, for a machine with one or two mouse-centric, forgetful users, yours is a nice implementation, and I'm sure a lot of people will prefer it.

Cheers

Frederico



[ Reply to This | # ]