Check for open app?

Hi,
I’m a little rusty, so could someone please remind me if it is possible to check to see if a specific app is open?
Any pointers would be appreciated, as I have been away from Xojo for over a year.

Thank you all in advance.

[quote=301452:@Richard Summers]Hi,
I’m a little rusty, so could someone please remind me if it is possible to check to see if a specific app is open?
Any pointers would be appreciated, as I have been away from Xojo for over a year.

Thank you all in advance.[/quote]

as you checking to see if the app you are starting it already open or another app on the system?

Also what O/S?

Hi Scott,
Im on macOS Sierra, and need to check to see if another app is already open.

Thanks.

I would open a new shell.
ps aux | grep -i {applcation name} | wc -l

and see the count of that {application name} that is running.

That code is from head and not tested. so you will have to work with it.

Thanks Scott - I will have as play around with it.

Thanks you very much.

[quote=301474:@Richard Summers]Thanks Scott - I will have as play around with it.

Thanks you very much.[/quote]

any time. I dont always have good advice… but I am willing to give my opinion.

I tried your solution, but whichever app name I enter, returns a result of 1 in the terminal.
I will have to research those terminal commands a little more :slight_smile:

Thanks.

http://documentation.xojo.com/index.php/Mutex

Mutex is great if I am trying to see if the same application as the one checking is running or not. If we are checking for a different application is running then mutex doesnt work.

On a Mac, to be on the safe side, I’d use AppleScript as a shortcut to a system call, and do it on the Shell for convenience. For example, to see if Xojo is running, use:

/usr/bin/osascript -e 'running of app id "com.xojo.xojo"'

This will either return “true”, “false”, or generate an error if the signature is not recognized, which is essentially the same as “false”. This technique also means that the actual app name will not matter, in case the user changed it.

[quote=301487:@Richard Summers]I tried your solution, but whichever app name I enter, returns a result of 1 in the terminal.
I will have to research those terminal commands a little more :slight_smile:

Thanks.[/quote]

Just type ps aux [return].

This will show you all apps running on your machine by the path to the app :

Mitchs-iMac:~ Mitch$ ps aux USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND Mitch 950 0.6 1.4 1192736 115160 ?? S 11:36AM 6:06.48 /Applications/Xojo 2016 Release 3/Xojo.app/Contents/MacOS/Xojo -psn_0_491640 _windowserver 196 0.3 0.4 3870092 33628 ?? Ss 9:54AM 6:15.71 /System/Library/PrivateFrameworks/SkyLight.framework/Resources/WindowServer -daemon Mitch 2472 0.3 0.5 2674844 42656 ?? S 10:59PM 0:02.85 /Applications/Utilities/Terminal.app/Contents/MacOS/Terminal Mitch 984 0.3 0.5 1089088 43300 ?? Ss 11:37AM 2:31.10 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/CoreServices/SpringBoard.app/SpringBoard Mitch 2471 0.0 1.4 3578220 120360 ?? S 10:56PM 0:11.98 /Applications/Google Chrome.app/Contents/Versions/54.0.2840.98/Google Chrome Helper.app/Contents/MacOS/Google Chrome Helper --type=renderer --enable-features=*AutofillCreditCardSigninPromo< root 2457 0.0 0.0 2494900 3772 ?? Ss 10:44PM 0:00.04 /usr/sbin/ocspd Mitch 2447 0.0 0.1 3022304 11256 ?? S 10:35PM 0:00.07 /System/Library/Frameworks/QuickLook.framework/Resources/quicklookd.app/Contents/MacOS/quicklookd Mitch 2417 0.0 0.4 2560760 35608 ?? Ss 10:11PM 0:00.19 /Applications/Utilities/Adobe Creative Cloud/CoreSync/Core Sync.app/Contents/PlugIns/ACCFinderSync.appex/Contents/MacOS/ACCFinderSync Mitch 2416 0.0 0.2 2541124 14208 ?? Ss 10:11PM 0:02.01 /Applications/Right Click Booster.app/Contents/PlugIns/RightClickBoosterPlugin.appex/Contents/MacOS/RightClickBoosterPlugin Mitch 2413 0.0 0.6 2627328 47384 ?? S 10:11PM 0:01.31 /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder Mitch 2403 0.0 0.0 2469640 2688 ?? S 10:10PM 0:00.01 /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HIServices.framework/Versions/A/XPCServices/com.apple.hiservices-xpcservice.xpc/Contents/MacOS/com.apple.hiser Mitch 2402 0.0 0.5 2744300 45488 ?? S 10:10PM 0:01.82 /Applications/Preview.app/Contents/MacOS/Preview Mitch 2357 0.0 0.0 2497064 3644 ?? S 10:02PM 0:00.05 /System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/Versions/A/Support/mdworker -s mdworker-sizing -c MDSSizingWorker -m com.apple.mdworker.sizing root 2282 0.0 0.0 2461752 300 ?? SNs 9:54PM 0:00.01 /usr/libexec/periodic-wrapper weekly root 2237 0.0 1.1 3039964 92584 ?? S 9:40PM 0:52.82 /Applications/Get Backup 2.app/Contents/MacOS/Get Backup 2 _spotlight 2212 0.0 0.1 2569520 10404 ?? S 9:37PM 0:00.29 /System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/Versions/A/Support/mdworker -s mdworker -c MDSImporterWorker -m com.apple.mdworker.shared Mitch 2152 0.0 0.2 2623208 14220 ?? S 9:05PM 0:00.76 /Applications/StrongVPN Client.app/Contents/MacOS/StrongVPN Client Mitch 1976 0.0 0.7 2545588 61104 ?? S 7:39PM 0:01.74 /System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/Versions/A/Support/mdworker -s mdworker -c MDSImporterWorker -m com.apple.mdworker.shared Mitch 1975 0.0 0.5 2537764 43376 ?? S 7:38PM 0:01.77 /System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/Versions/A/Support/mdworker -s mdworker -c MDSImporterWorker -m com.apple.mdworker.shared Mitch 1973 0.0 0.6 2543616 47588 ?? S 7:37PM 0:01.91 /System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/Versions/A/Support/mdworker -s mdworker -c MDSImporterWorker -m com.apple.mdworker.shared Mitch 1972 0.0 0.0 2471076 1296 ?? S 7:35PM 0:00.02 /usr/libexec/USBAgent Mitch 1971 0.0 0.0 2469944 1324 ?? S 7:35PM 0:00.01 /System/Library/PrivateFrameworks/KerberosHelper/Helpers/DiskUnmountWatcher Mitch 1908 0.0 0.0 3548204 3872 ?? Ss 7:16PM 0:00.05 /System/Library/Frameworks/WebKit.framework/Versions/A/XPCServices/com.apple.WebKit.Databases.xpc/Contents/MacOS/com.apple.WebKit.Databases Mitch 1904 0.0 0.2 2514168 12648 ?? S 7:16PM 0:01.72 /System/Library/PrivateFrameworks/SafariSafeBrowsing.framework/com.apple.Safari.SafeBrowsing.Service Mitch 1898 0.0 0.1 3578972 10288 ?? Ss 7:16PM 0:01.46 /System/Library/Frameworks/WebKit.framework/Versions/A/XPCServices/com.apple.WebKit.Networking.xpc/Contents/MacOS/com.apple.WebKit.Networking

What Scott posted is essentially a command to filter these results.

You can use a shell to ps aux, and get all this listing into Shell.Result, then use Instr() to find the app you are looking for.

What is tricky on Mac is the app looks like a folder. For instance

/Applications/Get Backup 2.app/Contents/MacOS/Get Backup 2

Get Backup 2.app shows you the whole path in the bundle to the Unix executable.

ps aux | grep -v grep |grep -i {applcation name} | wc -l

the grep -v grep says “and ignore the process DOING the grep” which will also be counted

EDIT : and NOT having the grep -v grep explains why you always get 1 - it counts the process that IS doing the grep and not finding anything else

alternatively you can just check for a value > 1

@Norman Palardy is right but he droped a grep in the line.

ps aux | grep -v grep | grep -i {applcation name} | wc -l

on a side note, I shouldnt write code from my head but use a computer. OR I would have caught I forgot the grep -v grep command.

whoops
cut & paste :stuck_out_tongue:

Thanks everyone!
I will sift through all those answers and obscure looking terminal commands, and see what happens. I will also try Kem’s suggestion, as that looks easier for my peanut brain to comprehend :slight_smile:

Thank you everyone - I really appreciate your help!

skip apple script :stuck_out_tongue:
lsappinfo list | grep -v grep | grep bundleID | grep | wc -l

lsappinfo has a TON of options :slight_smile:

Ok - even when Xojo is not running, the “Xojo is running” notification still displays??

Here is my code so far:

[code] // CHECK TO SEE IF XOJO IS RUNNING
Dim sh As New Shell
sh.Mode = 2
sh.execute “lsappinfo list | grep -v grep | grep bundleID | grep com.xojo.xojo | wc -l”

Dim shOutput As String = Sh.ReadAll
If shOutput = “0” Then

// DISPLAY A USER NOTIFICATION
m = New Module1.MyNotificationCenter
m.DeliverNotification(Module1.NSNotifications("Test App:","Xojo is not currently running."))

Else

// DISPLAY A USER NOTIFICATION
m = New Module1.MyNotificationCenter
m.DeliverNotification(Module1.NSNotifications("Test App:","Xojo is running."))

End if[/code]

Any help appreciated :slight_smile:

not really
just you check for the wrong kind of result
wc -l will return string but a string that holds “0” or some other value <> “0”
check for that not “false”

  // CHECK TO SEE IF XOJO IS RUNNING
  Dim sh As New Shell
  sh.execute "lsappinfo list | grep -v grep | grep bundleID | grep com.xojo.xojo | wc -l"
  
  Dim shOutput As String = Sh.Result
  If shOutput = "0" Then
    
    // DISPLAY A USER NOTIFICATION
    msgbox "Xojo is not currently running."
    
  Else
    
    // DISPLAY A USER NOTIFICATION
    
    msgbox "Xojo is running."
    
  end if

This is the code I now have, and it still tells me it is running, even when it’s not?

[code]// CHECK TO SEE IF XOJO IS RUNNING
Dim sh As New Shell
sh.Mode = 2
sh.execute “lsappinfo list | grep -v grep | grep bundleID | grep com.xojo.xojo | wc -l”

Dim shOutput As String = Sh.ReadAll
If shOutput = “0” Then

// DISPLAY A USER NOTIFICATION
m = New Module1.MyNotificationCenter
m.DeliverNotification(Module1.NSNotifications("Test App:","Xojo is not currently running."))

Else

// DISPLAY A USER NOTIFICATION
m = New Module1.MyNotificationCenter
m.DeliverNotification(Module1.NSNotifications("Test App:","Xojo is running."))

End if[/code]

In the terminal it says 0 when not running, and 1 when it is.
However, I keep getting shown the notification saying it IS running??

your using a mode 2 shell which does NOT give back a result instantly

I didn’t so the command runs and gives me the result IN the RESULT (not via readall)

subtle but important differences between what I posted and what you have