How do I check if app is running on Mac

I need to check if an Apple application is running on OSX from within my Xojo code. I know the bundle ID but can’t see how I can check if the process is active.

shell to

ps aux | grep nameoftheapp

with MacOsLibrary, checking --for instance-- if Skype is running::

[quote] for each runningApp as NSRunningApplication in NSWorkspace.RunningApplications if runningApp.BundleIdentifier = "com.skype.skype" then //do something return end if next Return false[/quote]

Thanks that exactly what I wanted to do.

How is that used if nameoftheapp has spaces e.g. My Favourite App

Dim Sh as new shell
Sh.Execute “ps aux | grep My Favourite App” //nameoftheapp is My Favourite App
msgbox Sh.Result

I would like the msg box to be “Yes” if it is and “No” if it is not.

Kindly advise.

Thanks.

Lennox

Call AppleScript ?

just put the app name in double quotes
like (I had to escape the - so the pattern would find things that contained “-c MDImporter”

 ps aux | grep "\\-c MDSImporter"

I did this…

Dim Sh as new shell
Sh.Execute ps aux | grep “My Favourite App” //nameoftheapp is My Favourite App
msgbox Sh.Result

and got this error…
This item does not exist ps

How can I fix that?

Thanks.

Lennox

have you searched the forums at all ?
this specific question has been answered many many times
try searching for “shell execute” and I’m sure you’ll get a pile of results

Hi Norman I searched but not for “shell execute”, I’ll do so now.

trying to find the answer on your own first is a good start - esp if someone is not online that can immediately answer your question
There are TONS of questions that have been answered
Searching isn’t esotalks fort so the search box at the top is only one option
you can also search using a custom google search noted on https://forum.xojo.com/30945-searching-tips

Because a SHELL is NOT the exact same as a terminal window (see https://forum.xojo.com/44112-where-does-the-shell-class-inherit-it-s-environment) what you CAN type into a terminal window may, as you’ve discovered, not work in a shell

the first thing to try is using the full path to the specific command - in this case “ps” is the command
you can find the full path to it by opening a terminal window and in there typing

which ps

which is yet another Unix command that tells you the full path to the app that you name after “which” (most things in Unix are small apps - ps is just another one of many)

so

which ps

tells you the full path to the ps application

the end result is you should try finding the answer on the forums first
that said your specific command should be

     Sh.Execute "/bin/ps aux | grep ""My Favourite App"" "

OK Norman,
Thanks.
Lennox