# outputs 1 if command is found, 0 otherwise.<br>running=`ps axco command | grep -c $appName`<br><br>if $running ; then<br> echo $appName found<br>else<br> echo $appname not found<br>fi<br><br><div class="gmail_quote">
On Fri, Mar 27, 2009 at 9:42 AM, Jerry Krinock <span dir="ltr"><<a href="mailto:jerry@ieee.org">jerry@ieee.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im"><br>
On 2009 Mar 27, at 05:01, Eric F Crist wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Sometimes, you need to add a few w's to the command to parse it properly:<br>
</blockquote>
<br></div>
Yes, it took me about 5 years of using bash to learn why ps didn't always work.<br>
<br>
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...<br>
<br>
# Assume that $appName is both the package name and the executable<br>
# name of the desired app. Warning: Either or both of these<br>
# assumptions can be wrong.<br>
appsRunning=`ps -alxww | grep -c "$appName.app/Contents/MacOS/$appName"`<br>
# If $appName is running, results count will be 2, the second<br>
# one being the grep process itself. Subtract that one.<br>
let "appsRunning -= 1"<br>
if (($appsRunning > 0))<br>
then<br>
echo "$appName is running"<br>
else<br>
echo "$appName is not running"<br>
fi<div><div></div><div class="h5"><br>
<br>
_______________________________________________<br>
X-Unix mailing list<br>
<a href="mailto:X-Unix@listserver.themacintoshguy.com" target="_blank">X-Unix@listserver.themacintoshguy.com</a><br>
<a href="http://listserver.themacintoshguy.com/mailman/listinfo/x-unix" target="_blank">http://listserver.themacintoshguy.com/mailman/listinfo/x-unix</a><br>
</div></div></blockquote></div><br>