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

Steve Morris barbershopsteve at gmail.com
Fri Mar 27 06:58:32 PDT 2009


 # outputs 1 if command is found, 0 otherwise.
running=`ps axco command | grep -c $appName`

if $running ; then
    echo $appName found
else
    echo $appname not found
fi

On Fri, Mar 27, 2009 at 9:42 AM, Jerry Krinock <jerry at ieee.org> wrote:

>
> 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
>
>
> _______________________________________________
> X-Unix mailing list
> X-Unix at listserver.themacintoshguy.com
> http://listserver.themacintoshguy.com/mailman/listinfo/x-unix
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.themacintoshguy.com/pipermail/x-unix/attachments/20090327/b1c90351/attachment.html


More information about the X-Unix mailing list