Vincent Gable’s Blog

April 24, 2009

How To Check if an Application is Running With AppleScript

Filed under: Programming,Sample Code | ,
― Vincent Gable on April 24, 2009
on ApplicationIsRunning(appName)
	tell application "System Events" to set appNameIsRunning to exists (processes where name is appName)
	return appNameIsRunning
end ApplicationIsRunning

Use it like,

if ApplicationIsRunning("Mail") then
	display dialog "Don't forget to write mom!"
end if

On Mac OS X 10.5, this worked for me even when the application-file’s name was changed. On 10.4 I do not expect that it would still work if someone renamed the application, unless you used the creator type to locate the process, not the name.

You might also be interested in how to get the name of the frontmost application, here’s how:

tell application "System Events" to set FrontAppName to name of first process where frontmost is true
if FrontAppName is "DVD Player" then display dialog "Get to work!" end if


  1. Thanks for this, I was looking for a way to autosave a program if it’s the front window. Super awesome thank you!

    Comment by Paul — May 17, 2012 @ 12:13 pm

  2. It might be easier to do this:

    if application “Mail” is running then

    end if

    Comment by Robert — April 25, 2013 @ 5:09 am

  3. I’ve used this successfully, to restart a crashed database but what can I do if the application is not responding? I would like to detect that it is not responding, force quit the application, and then restart it

    Comment by Pierre Coulombe — July 3, 2013 @ 2:19 pm

RSS feed for comments on this post.

Leave a comment

Powered by WordPress