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

10.3: Use fast user switching from the Terminal System
For those who love Panther's Fast User Switching but don't like the menulet in the upper-right corner, here's a shell script to do it.

#!/bin/sh
if [[ -z $1 ]]; then
  # robg note: Please enter the next two lines as one without
  # any spaces between the "/" and the "R"
  /System/Library/CoreServices/Menu\ Extras/User.menu/Contents/
  Resources/CGSession -suspend
else
  USERID=`id -u $1`;
  if [[ -z $USERID ]]; then
    exit -1;
  fi;
  # robg note: Please enter the next two lines as one without
  # any spaces between the "/" and the "R"
  /System/Library/CoreServices/Menu\ Extras/User.menu/Contents/
  Resources/CGSession -switchToUserID $USERID
fi;
Save the script in your path and make it executable (chmod 755 script_name). If it is called without any arguments, the script will switch to the login window. If called with a user name or id, it will bring up the password dialog and (assuming the correct password is entered) switch to that user.

This is especially useful because fast user switching does not have to be enabled in the account preferences for this hint to work.

[robg adds: Read the rest of the hint for my method of making this very cool script easy to use from the Finder...]

[robg adds: Here's a little trick to make it really easy to use. After you have it working, open a new Terminal window, make it as small as you can by dragging the corner, and then do File -> Save As (it doesn't matter what's in the window at the time). The default save location should be in your user's Libary -> Application Support -> Terminal folder. Give the saved file a name -- let's assume you want to fast switch to the login window, so call it "login." In the bottom section of the dialog box, click "Execute this command (specify complete path)" and then enter the path to your new script. In my case, it would be:

/Users/robg/bin/usw

Uncheck the "Execute coommand in a shell" box, and click Save. Now switch to the finder, and navigate to the ~/Library -> Application Support -> Terminal folder. Drag the "login.term" file into your sidebar, or your toolbar, or make an alias on your desktop, or whatever -- you'll be able to activate the login window just by clicking (in the sidebar or toolbar) or double-clicking (elsewhere) the icon!

To switch to another user instead, just create another saved window (rememer to make it tiny to make it less visually shocking), and for the "full path" bit, add the user's name to the script call:

/Users/robg/bin/usw testuser

In both cases, you'll see a tiny Terminal window appear, but then you'll either be taken directly to the login screen, or you'll get the switch user password dialog box. Wow! Side note: I changed my script name to usw from switch as sjonke commented that there's already a system-provided command by that name.]

    •    
  • Currently 2.78 / 5
  You rated: 3 / 5 (9 votes cast)
 
[64,486 views]  

10.3: Use fast user switching from the Terminal | 51 comments | Create New Account
Click here to return to the '10.3: Use fast user switching from the Terminal' 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 from the Terminal
Authored by: diamondsw on Nov 07, '03 11:14:59AM

Or you could use AppleScript's ability to run shell scripts and just place this on your script menu.



[ Reply to This | # ]
10.3: Use fast user switching from the Terminal
Authored by: nagani on Nov 07, '03 12:57:42PM

No need for AppleScript: just put the shell script in the ~/Library/Scripts/ folder...



[ Reply to This | # ]
10.3: Use fast user switching from the Terminal
Authored by: alajuela on Nov 07, '03 01:41:47PM

I like the idea of having this in the Scripts menu, because for me, the advantage is reclaiming the large amount of menubar real estate occupied by the current Fast Switch menu.



[ Reply to This | # ]
Context Menu
Authored by: jecwobble on Nov 07, '03 11:38:25AM

Perhaps even a context menu item using OnMyCommand.



[ Reply to This | # ]
10.3: Use fast user switching from the Terminal
Authored by: liquidgood on Nov 07, '03 12:06:58PM
i haven't tried it, but wouldn't you want to add ; exit to the end of the execution string so the tiny window will close (or does it do it automatically?).

[ Reply to This | # ]
10.3: Use fast user switching from the Terminal
Authored by: robg on Nov 07, '03 12:14:14PM

Good thought, didn't think to add that! :)

-rob.



[ Reply to This | # ]
10.3: Use fast user switching from the Terminal
Authored by: dmmorse on Nov 07, '03 01:45:40PM

doesn't seem to need it; the window is gone when I switch back



[ Reply to This | # ]
10.3: Use fast user switching from the Terminal
Authored by: fortrandragon on Nov 07, '03 12:36:31PM

Is there a reason why simply appending the .command extension to the shell script and dragging that to the sidebar won't work?



[ Reply to This | # ]
10.3: Use fast user switching from the Terminal
Authored by: discordantus on Nov 07, '03 01:17:18PM

this also makes it possible to switch to the root account, which I have been wanting to be able to do for a while



[ Reply to This | # ]
10.3: Use fast user switching from the Terminal
Authored by: Bottacco on Nov 08, '03 10:43:49AM

Well, you can do exactly that with Apple's solution. You just have to select the "Login Window" option in the menu and then type root and its password in the window that appears.



[ Reply to This | # ]
Use with CornerClick
Authored by: sjonke on Nov 07, '03 01:57:44PM
Make an applescript from this (all on one line):

do shell script "/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend"

Make sure you include two backslashes as shown. Save to a script file and then use the cool freeware CornerClick to trigger it by clicking in a particular corner of the screen. Better than corner triggering the screensaver for locking!

---
--- What?

[ Reply to This | # ]

Use with CornerClick
Authored by: Embro on Nov 07, '03 03:38:43PM

as you stated you need two backslashes after Menu and before the space

do shell script "/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend"

[ Reply to This | # ]
Use with CornerClick
Authored by: Embro on Nov 07, '03 03:39:49PM

as you stated you need two backslashes after Menu and before the space

do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -suspend"

[ Reply to This | # ]
Rob Please fix me!
Authored by: Embro on Nov 07, '03 03:45:48PM

DOH!
I guess that's why the original only showed one slash. The preview shows correctly when posting but the final posted one is not right. Thought I'd be clever and try to put three slashes in to show two....but no luck

Rob...Please fix this and delete my posts.

P.S. How come I can't delete my own posts?



[ Reply to This | # ]
Rob Please fix me!
Authored by: aranor on Nov 08, '03 01:31:32AM
I think you need 4 slashes to show two. Test: \\

[ Reply to This | # ]
Rob Please fix me!
Authored by: robg on Nov 29, '04 12:29:16PM
Actually, if you use the [ code ] tags (without spaces), as noted in red above the comment input box, then you can use one backslash for each one that you need to appear. Hence, it's supposed to look like this:
do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -suspend"
-rob.

[ Reply to This | # ]
10.3: Use fast user switching from the Terminal
Authored by: hangon on Nov 07, '03 02:44:06PM

very cool...but u know what ... the apple method is the best...



[ Reply to This | # ]
10.3: Use fast user switching from the Terminal
Authored by: Eravau on Nov 07, '03 03:03:26PM

The Apple method works best...unless you have little menu bar real estate and don't want your long username taking up the menu bar space.



[ Reply to This | # ]
10.3: Use fast user switching from the Terminal
Authored by: kenpen on Nov 07, '03 02:45:17PM

This works great. I also created an applescript that does the shell script. Then, as the coup de grace, I'm using Keyboard Maestro to map the applescript to Command+Option+L. That gives me a something similar (but far cooler) than the Windaos Ctrl+Alt+Del...Enter to lock my workstation.



[ Reply to This | # ]
Use with ScriptSaver
Authored by: sjonke on Nov 07, '03 03:03:36PM
If you install the ScriptSaver screensaver, you can also use the applescript to trigger the loginwindow at screensaver time (see thread about use with CornerClick for the applescript).

HOWEVER, you'll want to disable 10.3's screensaver/sleep lockout lest you have to enter your password twice, and doing that means losing lockout at sleep. Still it's pretty cool to have, in effect, the login window as your "screensaver". Note that ScriptSaver seems to have a minor incompatibility with 10.3 in that you can't use the browse button to find your script - it will crash System Preferences - instead you'll need to enter the path to your script manually. Once you've entered it correctly it works fine.

---
--- What?

[ Reply to This | # ]

Timer Script countdown
Authored by: catodysseus on May 02, '04 12:32:03AM

Wery nice!

But I would like a timer script making the log out after 30 min or so. My setup activates the ScriptSaver screen saver after 5 min and a script start iWannaSleep timer set to run the shell script (and pause iTunes) after 30 min.

Now if someone will help me write a Script doing the countdown I can skip iWannaSleep program, since if i get back to puter within 30 min I'll have to quit the app manually.

When doing the log in from FUS menu I use FUS++ to quit iWannaSleep and get iTunes playng again.

---
"I got such a long way to go till make it to the border of Mexico"
Saxon



[ Reply to This | # ]
robg's example ("switch")
Authored by: sjonke on Nov 07, '03 03:17:30PM

Note that "switch" is a built-in shell command, so calling the script "switch", as in robg's example, may not be the best choice.

---
--- What?



[ Reply to This | # ]
robg's example ("switch")
Authored by: robg on Nov 07, '03 03:22:44PM

Heh, thanks! That's what I get for working too early in the morning. My script is now <tt>usw</tt>, which is even easier to type :)

-rob.



[ Reply to This | # ]
10.3: Menu Bar Item Modification?
Authored by: Telluride on Nov 07, '03 03:17:36PM

Anyone know if its possible to just change the Fast User Switching Menu Item from your current username to just a small icon? I like fast user switching, but haven't really used it that much mainly because it takes up WAY to much menubar real-estate. I'm sure it is possible to change somehow, but looking at the plist file hasn't enlightened me yet.



[ Reply to This | # ]
10.3: Menu Bar Item Modification?
Authored by: sjonke on Nov 07, '03 04:11:34PM

In NetInfo Manager change everyones "realname" to be a symbol character, like the artist formerly not called Prince. ;) For kicks I tried it and it works. Now just have to remember who is the airplane, who is the pair of scissors, who is the cross,....

---
--- What?



[ Reply to This | # ]
Yes, it's possible, here's how:
Authored by: Rainy Day on Apr 27, '06 03:03:11PM

In Tiger, just go to Accounts in System Preferences, and click on "Login Options" (look for the house icon on the left side). You'll then see an "Enable Fast User Switching" option; below it is a "View as" pop-up menu. Choose "Icon."

Not sure if this is available under Panther or not?



[ Reply to This | # ]
10.3: Use fast user switching from the Terminal
Authored by: diamondsw on Nov 07, '03 04:13:35PM

Given the information here, I think it would be great if some freeware developer slapped together a menu extra to replace the Apple one. That and a screen saver that automatically "locks" the screen using this (ala the ScriptSaver comment above).



[ Reply to This | # ]
10.3: Use fast user switching from the Terminal
Authored by: makaio on Nov 07, '03 05:25:50PM

I'm actually putting together a little app to do that right now. I should have a beta-quality version ready in the next day or so -- when I do, I'll post a link.



[ Reply to This | # ]
10.3: Use fast user switching from the Terminal
Authored by: Xeo on Nov 08, '03 02:27:34PM

If you're making your own FUS menu, to replace Apple's that's terrific. Imagine all the features it could have! It could display anything you want as the item itself, but still list full names. It could have the option to QUIT ITUNES! and solve that problem. It already stops playing so I'd love the option to quit it automatically as well. I hate it when the little sister leaves it open.

There are many other features that could be wrapped into this little menuling. And the great part about it is that no one would know otherwise, as far as the average user goes. As the admin, I can set it up in everyone's account and they can use it normally as if it's the Apple branded one. Amazing!



[ Reply to This | # ]
10.3: Use fast user switching from the Terminal
Authored by: wahoo252 on Nov 07, '03 07:04:52PM

- check out the freeware FUSKey (Fast User Switch Key) on VersionTracker :

http://www.versiontracker.com/dyn/moreinfo/macosx/21371

- it allows you to toggle fast user switching, just using a keyboard shortcut. -no need to have the user switching item in the menubar.



[ Reply to This | # ]
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 | # ]
Even cooler
Authored by: deleted_user18 on Nov 08, '03 03:33:33AM

If you put something like this into your .tcshrc

complete this_script 'p/*/u/'

you can browse through your users using the tab key.



[ Reply to This | # ]
I wrote a screen saver to do this.
Authored by: rselph on Nov 08, '03 11:11:56AM
I just finished writing a very simple screen saver that will do this. i.e. As soon as the screen saver is invoked, it switches over to the login screen. You can find it (with source code) on my public iDisk (user name rselph), or here.



[ Reply to This | # ]

I wrote a screen saver to do this.
Authored by: mm2270 on Nov 08, '03 11:24:01AM

Hey, that actually works rather nice, but, it isn't really a screensaver perse is it? It just goes to the log-in screen. What would be nice is if it went to the log in screen, but then invoked a real screensaver or dimmed the screen or something. Then it would be more useful. But nice work so far.



[ Reply to This | # ]
I wrote a screen saver to do this.
Authored by: rselph on Nov 08, '03 11:34:38AM

AFAIK, what you suggest isn't possible. Once the program has been invoked to switch to the login screen, the system has complete control. I could invoke another saver, but it would be hidden.



[ Reply to This | # ]
Cool!
Authored by: bipto on Nov 09, '03 11:11:47PM

Hey, now that's pretty darn cool!

Thanks!



[ Reply to This | # ]
The link changed to this...
Authored by: ryanhunt on Sep 10, '06 06:44:40AM
Just tried to find this and the link had changed. By back tracking I was able to find the right link which is:

http://homepage.mac.com/rselph/FileSharing19.html

-Ryan

---
Ryan Hunt
http://www.hunthost.com/
http://www.ryanhunt.info/

[ Reply to This | # ]

The link changed to this...
Authored by: ryanhunt on Sep 10, '06 06:47:13AM

Actually when I downloaded the file it contained a number of screensavers, but none that I could identify as the one referenced above.

---
Ryan Hunt
http://www.hunthost.com/
http://www.ryanhunt.info/



[ Reply to This | # ]
10.3: Use fast user switching from the Terminal
Authored by: MVasilakis on Nov 11, '03 02:45:23PM

If I wanted to add code to kill the osxvnc service with this how would I do it?



[ Reply to This | # ]
10.3: Use fast user switching from the Terminal
Authored by: CrankyMacGuy on Feb 21, '04 06:11:26PM

Running "top" I see the following added to the list of processes once OSXvnc is run:

OSXvnc-ser
fix_prebin
OSXvnc

OSXvnc-ser is the process you'll see once a server is running. I don't know what fix_prebin is. "killall OSXvnc" will take care of the first two, but fix_prebin is a system process and needs "sudo" to remove. I don't know if that helps you or not, but I think for a quick fix you can leave "fix_prebin" running. It's a sloppy solution, but I don't know how to pass a password to "sudo" via script... :)

---
~Life...don't talk to me about life.



[ Reply to This | # ]
Remove the User Switch Menu for you but leave it for others
Authored by: tlunde on Nov 14, '03 11:06:16AM

If you're interested in this hint so that you can reclaim menu bar space for yourself, but don't want other users of the system to have to remember the terminal incantations:

1. Turn FUS on in the System Preferences -> Accounts
2. Edit ~/Library/Preferences/com.apple.systemuiserver.plist

Remove the line that is:
<string>/System/Library/CoreServices/Menu Extras/User.menu</string>

Log out, and then in again. _Your_ menubar will be cleaner, but when any other user logs in, their menubar will look normal.



[ Reply to This | # ]
Remove the User Switch Menu for you but leave it for others
Authored by: asan102 on Mar 09, '04 06:54:43PM

Just command-dragging a menu item out of the menu bar will remove it form the preferences, and it won't show up next time you log in – no need to manually edit the preference file.



[ Reply to This | # ]
A menu to replace Apple's
Authored by: makaio on Nov 17, '03 04:50:52PM
For anybody that comes to this hint looking for a free replacement to Apple's menu, I've put together an open source application to do so. The project is at fus.sourceforge.net. It allows, among other things, for you to replace the long username with either your user picture or your short username. See the website for more information.

[ Reply to This | # ]
10.3: Use fast user switching from the Terminal
Authored by: mrr1 on Dec 20, '03 06:46:30PM

Did this break in 10.3.1 or 10.3.2



[ Reply to This | # ]
How about sending a PASSWORD?
Authored by: jporten on Jan 07, '04 01:40:26AM

Guys, I'm impressed with the dedication to saving a few pixels of menu bar space.

But how about some information on modifying this script so I can switch to one of my other users without entering that darned password every time? The obvious answer, adding a -password flag, doesn't work.



[ Reply to This | # ]
How about sending a PASSWORD?
Authored by: CrankyMacGuy on Feb 21, '04 06:15:49PM

I'd like to see this too. I often log into my friends laptop via OSXvnc and use his cable connection to grab large Bit Torrents. However, sometimes he forgets to log into my account. OSXvnc continues to broadcast the screen despite switching users, but it won't allow me to share the display so I can't switch it back! :/ Being able to switch via terminal while passing a password along would make this a non issue. If you ever figure it out, please drop me an email at http://www.cootey.com/email.html Thanks!

---
~Life...don't talk to me about life.



[ Reply to This | # ]
10.3: Use fast user switching from the Terminal
Authored by: mbdayton on Jan 13, '06 02:18:24PM

What sort of modifications would you have to make to have this script work in Tiger?



[ Reply to This | # ]
10.4: Tiger version
Authored by: mzs on Apr 20, '06 11:00:29AM
mbdayton posted that this no longer works in Tiger. I have the following working in 10.4.

I have this script: ~/bin/fus


#!/bin/sh
# Fast User Switching from the command line

CGSession='/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession'

case "$#" in
    0)
        # display login screen
        exec "$CGSession" -suspend
        exit
        ;;
esac

# No reason to display the login panel for the current user
case "$1" in
    "$USER" | "$UID")
        exit 0
        ;;
esac

# can pass in a (short) username or userid
id=`/usr/bin/id -u "$1"` || exit

# display login panel for user
exec "$CGSession" -switchToUserID "$id"
It is basically the same code as before but it can take a userid (501 for example) or username (unix short name in Mac parlance) as an argument. It also first checks to see if you are changing to the current user.

Then I create a symlink to ~/bin/fus in ~/Library/Scripts:


ln -s ~/bin/fus ~/Library/Scripts/Login\ Window
Now I can select "Login Window" from the AppleScript menu to switch to a different user.

To be able to switch to some particular user without going through the Login Window first, I make this script too: ~/Library/Scripts/.fus


#!/bin/sh
exec "$HOME"/bin/fus `/usr/bin/basename "$0"`
It starts with a dot (.) so that it does not show-up in the AppleScript menu. If you make links to .fus it will call fus with whatever name you gave to the link. (Remember that you need to make both fus and .fus executable.)

Now for every user that I want to be able to switch to directly from the AppleScript menu I do the following in the Terminal:


ln ~/Library/Scripts/.fus ~/Library/Scripts/foo
Where "foo" is the username of the user. It is very important that you make a hardlink instead of a symlink because for whatever reason when you run the script from the AppleScript menu the symlink is resolved to the .foo file and then the .foo script has no way of knowing which user to switch to.

Then from the AppleScript menu I can choose "foo" and up pops the panel asking for the user password.

[ Reply to This | # ]

Zombie processes
Authored by: mzs on Apr 20, '06 01:17:04PM
I have been using this for a quile and I just noticed that in Tiger at least this approach leaves many zombie process around beacause SystemUIServer never reaps the exit status of the .fus and fus shell scripts.

  9608 /System/Library/CoreServices/SystemUIServer.app/Contents/MacOS/SystemUIServer -psn_0_91226113
    19123 (sh)
    19224 (CGSession)
    19229 (CGSession)
    19249 (sh)
    19253 (sh)
    19256 (sh)
    19259 (sh)
    19262 (sh)
    19273 (sh)
    19276 (CGSession)
    19283 (CGSession)
    19302 (CGSession)
    19332 (CGSession)
    19341 (CGSession)
    19389 (CGSession)
    19035 (CGSession)
That is a bug. Here is a work around. If the scripts in the ~/Library/Scripts folder are AppleScripts instead of Bourne shell scripts, then there is no exit status to reap, and hence no zombie processes remain.

First remove these files (remember that Login Window is a link to fus so it is important to delete these first):


rm ~/Library/Scripts/Login\ Window ~/Library/Scripts/.fus
Now for every user that you created a link to .fus for, do a command like this but replace "foo" with the approppriate username:

rm ~/Library/Scripts/foo
Create this AppleScript ~/Library/Scripts/.fus.scpt:

-- get the home dir
set H to quoted form of (system attribute "HOME")

-- get name of script
tell application "Finder" to set N to name of (path to me)

-- escape special characters
set N to quoted form of N

-- call fus to switch user
do shell script H & "/bin/fus `/usr/bin/basename " & N & " .scpt`"
Again the name begins with a dot (.) so that it does not appear in the AppleScript menu. This AppleScript calls fus with its own name (minus the .scpt extension) in a similar vein as .fus originally worked.

Now we need to create the "Login Window" script in the AppleScript menu. It too cannot be a link to a Bourne shell script anymore because there will be zombie processes remaining. But since the name trick is not being played with it, this AppleScript is very straigh forward. Here is my '~/Library/Scripts/Login Window.scpt':


-- get the home dir
set H to quoted form of (system attribute "HOME")

-- call fus to get Login Screen
do shell script H & "/bin/fus"
Remember to make links to .fus.scpt for each user you want to switch to directly like so:

ln ~/Library/Scripts/.fus.scpt ~/Library/Scripts/foo.scpt
Now you would have an entry in the AppleScript menu for the user "foo". The ".scpt" extension will not show-up in the AppleScript menu so you might as well use it. If you do not want to use the extension that is fine too, the .fus.scpt will deal with that as well. Just do not use any other extension because then it will not work.

[ Reply to This | # ]