Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Force Quit Process by name

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)

Posted on Mar 4, 2007 10:49 AM

Reply
Question marked as Best reply

Posted on Mar 4, 2007 11:19 AM

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.
9 replies
Question marked as Best reply

Mar 4, 2007 11:19 AM in response to JSWolf

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.

Mar 6, 2007 10:22 AM in response to JSWolf

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.

Force Quit Process by name

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.