blog advertising is good for you


blog advertising is good for you
User login

Script Menu Scripts

Hey JC, I’m no good at AppleScript. Could you revise your tip so I can just drop it into Script Menu?

I realized recently that there’s a little known feature of Script Menu that I’ve been using without a second thought. As it turns out, Script Menu isn’t just for AppleScript. It can handle any kind of script. Perl, Python, Shell, AppleScript, whatever. Make any script like you normally would (making sure to make it is executable, if necessary!) and drop it in ~/Library/Scripts. About half of mine are shell, half Perl. Here’s a sample.

Average rating
(0 votes)
About JC
JC's picture

Author Biography

JC is a former Mac Genius and Mac-centric IT worker with a background in print advertising. He earned a reputation as a miracle worker when he saved the day at a new business pitch with the arcane knowledge that Apple’s ADB cables were nothing more than poorly shielded S-Video cables.

JC runs the Heroic Efforts Data Recovery Service and writes Ungenius, a tawdry tale of the life and times of a former Mac Genius.

You can contact JC via IM or via the contact form.

Does using the script menu to run non-Applescript scripts leave zombie processes on your system?

I have a script like this in a subdir of my ~/Library/Scripts directory:

#!/bin/sh
exec say 'boo!'

When I run it, I end up with a new zombie process:

$ ps -auxww | grep Z
...
user 14643   0.0  0.0        0      0  ??  Z    31Dec69   0:00.00 (say)

I haven’t tried every type of “script”, but Bourne shell (sh) and Perl scripts seem to trigger this reliably. At one point, I had a couple of Bourne shell scripts that I was running several times a day, and ended up hitting my per-user process limit. The default limit on my system is 100. You can check your own process limit with ulimit -u (in Bourne derived shells: sh/bash/ksh;zsh) or limit maxproc (in C-shell derived shells: csh/tcsh). Once the number of my normal processes and zombie processes reached 100, I couldn’t launch new applications. Eventually I had to logout to clear up all the zombies.

The bug appears to be in SystemUIServer. A modified version of the same script is below. If you run it, then check the log file and process listing, you can see who the non-reaping parent process is:

#!/bin/sh
exec > /tmp/boo.log # redirect stdout to log file
echo "boo PID: $$"
echo "boo PPID: $PPID"
exec say 'boo!'

$ cat /tmp/boo.log 
boo PID: 14749
boo PPID: 309
$ ps -auxww | grep 14749
user 14749   0.0  0.0        0      0  ??  Z    31Dec69   0:00.00 (say)
$ ps -auxww | grep 309
user   309   0.0  2.6   117968  17100  ??  S    Tue07PM   1:16.85 /System/Librar
y/CoreServices/SystemUIServer.app/Contents/MacOS/SystemUIServer -psn_0_524289

(I inserted a line break in that last line to keep the text from being horribly wide)

This is all on 10.3.5 here.

So, does anyone else have this same problem? If so, does anyone know of a good way to see if this bug has already been reported to Apple? If not, should I just report it and let them deal with any duplication?

Adam Knight's picture

It’s the exec statement When I ran just:

#!/bin/bash
say "boo!"

There were no zombies. When I ran:

#!/bin/bash
exec say "boo!"

… there were. No need for exec anyhow. Anyway, to get rid of the zombies, kill the SystemUIServer (odd name for “that thing that runs menu items” but that’s what it is). It will reload and your items will come back.

cp

Nice to know that SystemUIServer will be relaunched if it is killed. However, not using exec in the scripts on my system doesn’t prevent the zombies, just changes their “name”.

If I just delete the exec from my “/bin/sh“ version, I get this zombie:

user 15784   0.0  0.0        0      0  ??  Z    31Dec69   0:00.00 (sh)

If I switch to the script to bash (the exact same script text as your first example in the parent to this post (comment 51)), I get this zombie:

user 15792   0.0  0.0        0      0  ??  Z    31Dec69   0:00.00 (bash)

So, when using exec, the process listing displays the zombie as “(say)”, but it doesn’t seem to cause the zombie, at least not on my system. Maybe I just have a mutant system. Laughing out loud

Adam Knight's picture

Yeah, now that I look I have it too. SystemUIServer is broke. Bug report time. :\

cp

Post new comment
The content of this field is kept private and will not be shown publicly.
2 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.