9 Replies Latest reply: Mar 11, 2007 5:25 PM by kel
JSWolf Level 1 Level 1 (85 points)
Hi,
I was wondering if it was possible to make a script that looks like this:
repeat
check to see if thisProcess (where thisProcess is a process name instead of a process id) is running
if (true) then
force quit thisProcess
end if
end repeat

[end]

Thank you

Intel iMac 2.0 GHz, Mac OS X (10.4.8)
  • 1. Re: Force Quit Process by name
    Camelot Level 8 Level 8 (45,790 points)
    You can use the shell command killall to kill a process by name. To incorporate that in your AppleScript you'd do something like:

    <pre class=command>tell application "System Events"
    -- is it running?
    if (application process "Safari" exists) then
    -- kill it
    do shell script "killall Safari"
    end if
    end tell</pre>

    Note that you can also eschew checking if the app is running - if it's not, killall will just throw an error which you can trap via:

    <pre class=command>try
    do shell script "killall Safari"
    end try</pre>

    If it's running, it will be killed. If it's not, the try/end try will suppress the error message.
  • 2. Re: Force Quit Process by name
    JSWolf Level 1 Level 1 (85 points)
    it works but doesnt do what i want it to do.
    i would like it to close a menubar process
  • 3. Re: Force Quit Process by name
    kel Level 3 Level 3 (850 points)
    Hi Wolf,

    What menu bar process?

    gl,
  • 4. Re: Force Quit Process by name
    JSWolf Level 1 Level 1 (85 points)
    just any one
  • 5. Re: Force Quit Process by name
    kel Level 3 Level 3 (850 points)
    Is it one of those .menu menu extras like the date and time?

    You probably know this, but you can just press Command + drag the menu bar item out of menu bar. You know this right?

    gl,
  • 6. Re: Force Quit Process by name
    Camelot Level 8 Level 8 (45,790 points)
    The standard menu extras are managed by the SystemUIServer, so can't be addressed in this way.

    You're probably going to need to do something like edit SystemUIServer's preferences and log out/in.

    <pre class=command>do shell script "defaults read com.apple.systemuiserver menuExtras"</pre>

    will give you a list of the active menu extras. You can use defaults write to edit the settings.
  • 7. Re: Force Quit Process by name
    kel Level 3 Level 3 (850 points)
    Hi,

    The nice part about menu extras in com.apple.systemuiserver.plist is that it's an array in the first level. Easy to modify.

    Just thought of something. Maybe you can reset the menu by restarting SystemUIServer if you need to.

    gl,
  • 8. Re: Force Quit Process by name
    JSWolf Level 1 Level 1 (85 points)
    its not a standard menu extra. its a menubar application that won't stay closed. i can close it with the activity monitor, but it just re-opens and the pid is changed each time.

    Intel iMac 2.0   Mac OS X (10.4.8)  
  • 9. Re: Force Quit Process by name
    kel Level 3 Level 3 (850 points)
    So, you need to script the application, changing its preferences to not place the icon in the menu bar. It's hard to find if it can be done without having that application or even knowing what it is.

    gl,