{"id":300,"date":"2009-04-24T19:46:39","date_gmt":"2009-04-25T00:46:39","guid":{"rendered":"http:\/\/vgable.com\/blog\/2009\/04\/24\/how-to-check-if-an-application-is-running-with-applescript\/"},"modified":"2009-04-25T14:51:07","modified_gmt":"2009-04-25T19:51:07","slug":"how-to-check-if-an-application-is-running-with-applescript","status":"publish","type":"post","link":"https:\/\/vgable.com\/blog\/2009\/04\/24\/how-to-check-if-an-application-is-running-with-applescript\/","title":{"rendered":"How To Check if an Application is Running With AppleScript"},"content":{"rendered":"<pre>\non ApplicationIsRunning(appName)\n\ttell application \"System Events\" to set appNameIsRunning to exists (processes where name is appName)\n\treturn appNameIsRunning\nend ApplicationIsRunning\n<\/pre>\n<p>Use it like,<\/p>\n<pre>if ApplicationIsRunning(\"Mail\") then\n\tdisplay dialog \"Don't forget to write mom!\"\nend if<\/pre>\n<p>On Mac OS X 10.5, this worked for me even when the application-file&#8217;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 <code><strong>creator type<\/strong><\/code> to locate the process, not the <code>name<\/code>.<\/p>\n<p>You might also be interested in how to get the name of the frontmost application, here&#8217;s how:<\/p>\n<pre>tell application \"System Events\" to set <strong>FrontAppName<\/strong> to name of first process where frontmost is true<br>\nif FrontAppName is \"DVD Player\" then\n\tdisplay dialog \"Get to work!\"\nend if\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>on ApplicationIsRunning(appName) tell application &#8220;System Events&#8221; to set appNameIsRunning to exists (processes where name is appName) return appNameIsRunning end ApplicationIsRunning Use it like, if ApplicationIsRunning(&#8220;Mail&#8221;) then display dialog &#8220;Don&#8217;t forget to write mom!&#8221; end if On Mac OS X 10.5, this worked for me even when the application-file&#8217;s name was changed. On 10.4 I do [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,13],"tags":[45,397],"class_list":["post-300","post","type-post","status-publish","format-standard","hentry","category-programming","category-sample-code","tag-apple-script","tag-system-events"],"_links":{"self":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts\/300","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/comments?post=300"}],"version-history":[{"count":0,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts\/300\/revisions"}],"wp:attachment":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/media?parent=300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/categories?post=300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/tags?post=300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}