[X-Unix] Command to find if a certain app is running?

Jerry Krinock jerry at ieee.org
Fri Mar 27 06:42:03 PDT 2009


On 2009 Mar 27, at 05:01, Eric F Crist wrote:

> Sometimes, you need to add a few w's to the command to parse it  
> properly:

Yes, it took me about 5 years of using bash to learn why ps didn't  
always work.

Anyhow, thanks Christoph.  I was hoping there might be something that  
would identify an app from Launch Services database, but  then I  
figured that since I'm mainly concerned with false alarms and can  
tolerate misses, I could use ps and grep...

# Assume that $appName is both the package name and the executable
# name of the desired app.  Warning: Either or both of these
# assumptions can be wrong.
appsRunning=`ps -alxww | grep -c "$appName.app/Contents/MacOS/$appName"`
# If $appName is running, results count will be 2, the second
# one being the grep process itself.  Subtract that one.
let "appsRunning -= 1"
if (($appsRunning > 0))
then
echo "$appName is running"
else
echo "$appName is not running"
fi



More information about the X-Unix mailing list