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

10.3: Launch iTunes even if it's running elsewhere Apps

I resented the fact that I could not launch an application if another user logged into my computer had left it open. Here is the solution to launch an application another user has left active in Panther, with the example of iTunes.

  1. We need a shell script that will explore processes and kill if it finds one
  2. We need this shell script to have administrator privileges, even for the "Guest" account
  3. We want to wrap around this shell script a nice GUI
Read the rest of the hint for the solution...

[robg adds: The following script will quit iTunes, regardless of where it was launched. Just remember to check first before trashing someone's iTunes; it's possible that iTuness may be busy re-sampling all MP3s when you merrily toss it out of existence!]

  1. The shell script to quit iTunes left open by another user:
    ok=`/bin/ps -auxww | /usr/bin/grep | /usr/bin/grep -vc grep` ; ko=1
    if test $ok = $ko; then
      kill `ps -ax | grep | grep -v grep | awk '{print $1}'`
    open -a "iTunes"
    If you're new to shell scripting, do this:
    • Copy the code above
    • Open Terminal in Application > Utilities
    • Type emacs /
    • Type Command-V
    • Type Control-X then Control-S (to save)
    • Type Control_X Control-C to quit emacs)

  2. Now we need to execute the script with administrator privileges. I presume you have named your script, and that it is at the root of your OS X disk. Copy and paste these lines, one by one, into the Terminal:
    % sudo chown root /
        #(you will be prompted for admin password)
    % sudo chmod +x /
    % sudo chmod u+s /
    This changes ownership of the script to root, makes it executable, and operates with root privileges when executed.

  3. Now we need a nice GUI around this. Launch Script Editor in Applications -> Applescript, and copy and paste the following:
    do shell script "/"
    Save your AppleScript as an application, leaving all options checkboxes blank, give it the name you want in the place you want. To launch iTunes, double-click on it.

    Bonus: I wanted my AppleScript to have the same icon as iTunes and place it in my dock. Find your iTunes in folder Applications. Click on it. Hit Command-I (to open the information window). Then click on the icon. Hit Command-C (to copy the icon). Now close information window of iTunes and open that of your script. Instead of hitting Command-C, hit Command-V (to paste the icon). You're set!

    Repeat step three for each of your users. This is it. Security concerned? No, iTunes won't be launched with root privileges by the shell script. The command open -a launches an application with its normal privileges.

  • Currently 1.25 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)

10.3: Launch iTunes even if it's running elsewhere | 6 comments | Create New Account
Click here to return to the '10.3: Launch iTunes even if it's running elsewhere' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.3: Launch iTunes even if its running elsewhere
Authored by: kirkmc on Nov 16, '03 03:53:44AM

If you're an admin, just open Activity Monitor and quit iTunes from there. Sure, it's a GUI solution and not a shell script, but it's a heck of a lot easier.

[ Reply to This | # ]
10.3: Launch iTunes even if its running elsewhere
Authored by: adrianm on Nov 16, '03 04:01:30AM
Another way around this problem is to launch it directly.

In Terminal:


iTunes will run regardless of whether it was started someplace else.

This is probably a bit less drastic than becoming the superuser and killing off other people's processes.

This hint can of course be wrapped in a do shell script applescript and placed, say, in the dock as Emergency iTunes. Examples of that are elsewhere so can leave as an example to the reader.

[ Reply to This | # ]

10.3: Launch iTunes even if its running elsewhere
Authored by: dmackler on Nov 16, '03 01:13:51PM

Or, more cleanly, replace the kill command with the following:

osascript -e 'Tell application "iTunes" to quit'

and that will do a clean GUI quit. This must run administrator rights, just as the command within the hint does.


[ Reply to This | # ]
10.3: Launch iTunes even if its running elsewhere
Authored by: persson on Nov 16, '03 10:22:43AM
Not that there is anything wrong with grep, awk and ps, but it looks like the command:
killall iTunes
may well suffice for the first step of this hint.

Check out the -u, -l and -s to make this command a bit safer.

[ Reply to This | # ]

setuid scripts are insecure!
Authored by: hayne on Nov 16, '03 01:59:49PM
It is generally considered that setuid root shell scripts are insecure and hence should not be used. (The 'chmod u+s' makes the script setuid - i.e. it runs with the priviledges of the owner, which is root.) The setuid facility should only be used for compiled executables where the insecurity is much less. Or write the script in Perl and use the 'taint' facility.

Instead of making the script setuid, you should run it with 'sudo'.

Reference on the insecurity of setuid root scripts:
Sys Admin magazine

[ Reply to This | # ]

Try either pidof or killall
Authored by: cubal on Jan 14, '04 07:27:27AM

Also check out `pidof` which returns the process id of a named process. However, like another poster said, killall is probably the way to go.

killall iTunes
kill `pidof iTunes`
will do exactly the same thing - and neither need to be checked. If there's no 'iTunes', they'll just not do anything.

[ Reply to This | # ]