How to check if Application is running in Applescript

Hello,


due to the lack of ability to turn off the display on an iMac, I am forced to use a 3rd party application called "Shades" to greatly dim the display when using Airplay or watching a movie on my second monitor. Due to the odd way Shades operates, the application will dim the display to the previous settings on login. Therefore every time I login, my display goes dark and I must use a keystroke defined by Shades to restore the display brightness.




I have written an Applescript to remedy this:




do shell script "sleep 4"


tell application "System Events" to key code 27 using command down


quit




The problem I have now is: if I was not running shades on my last session, when I login, the Applescript gives this error:


“Application isn’t running.”


Is there an Applescript command (or shell command I can run withing Applescript) to check if Shades is running before executing the rest of the script?

iMac, 14,3 21.5, 16GB DDR3 256GB-OTHER, OS X Mavericks (10.9.5), i7 4770s 3.1GHz Quad

Posted on Dec 9, 2014 12:24 AM

Reply
1 reply

Dec 9, 2014 12:35 AM in response to Apple_Hero78

There are various ways of doing this. One is to ask System Events for a list of all running processes and just check for the one in question:


tell application "System Events"

if (get name of every application process) contains "Shades" then


-- your code here

end if

end tell


You may need to check how the app presents itself to System Events. Some use the short application name (e.g. 'Shades') while others, especially backgound apps, may use application IDs such as 'com.apple.WebKit.WebDeveloper', but a quick check of the output of 'every application process' should be easy enough.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to check if Application is running in Applescript

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