See if app is running & quit it

I’m trying to see if an application is running, and if it is, then quit it. I tried these two lines of code:

if application "Internet Explorer" is active then
		tell application "Internet Explorer" to quit

but they don’t seem to work. How can I properly code this?

Try this:

if (list processes) contains "Mail" then
	tell application "Mail" to quit
end if

HTH -john

I got an error – “The variable process is not defined.”

==========
set targetApp to “application”

tell application “System Events”
set processExists to exists process targetApp
end tell

if processExists is true then
tell application “application”
quit
end tell
end if

Can I ask what version of the System software you are running? The term “process” only recently became supported in osX. Up until 10.2.4 or .5 it was still listed as unimplemented according to the finder dictionary. I ran my version of the script on 10.2.6 it should also work in os 9.

You can try this in versions of osX older than 10.2.6

set psList to do shell script "ps -auxw | grep "Mail""
if psList contains "Mail.app" then tell application "Mail" to quit

-john

I’m using 10.2.6.

Perhaps mipadi put the code out of a Finder “tell block”, but this may work:

tell application "Finder" to if (list processes) contains "Mail" then tell application "Mail" to quit

Also, to retrieve a parsed list of name of processes, you can try this:

tell app "Finder" to name of processes

You could do it like this.


do shell script "kill `ps ax | grep Preview.app | grep -v grep | cut -d" " -f2`"

Yep! But kill a process is not the same as “quit” it…