Welcome, Daring Fireballers!
What I find interesting is that we can even have multiple ways to accomplish things like this. Not sure how the Leading Brand affords it users this kind of power . . . .
But so how do you test if an application is currently running?
There’s More Than One Way to Do It: Gruber suggests this method.
white:~ paul$ time osascript -e ‘tell app “System Events” to count processes whose name is “Finder”’
But it takes anywhere from 1 to 5 seconds: spinning up AppleScript to call an application is expensive.
This method takes a little less time:
white:~ paul$ time ps auxwww | grep -v grep | grep -c Finder
And it could be even more concise if you didn’t care about the count: Gruber’s initial question is “is an application running?” but he is actually doing more than that by returning a count. That could be a limitation/feature of AppleScript.
If you were married to AppleScript or somehow need this to be a double-clickable item, you could make a script file that wraps the icky terminal commands:
set theCommand to “ps auxwww | grep -v grep | grep -c Finder”
do shell script theCommand
It’s a nice compromise: slower than the command line but faster than a pure AppleScript solution.
white:~ paul$ time osascript test.scpt