# Check for open app?

**URL:** <https://forum.xojo.com/t/check-for-open-app/34786>\
**Category:** General\
**Created:** [December 4, 2016, 6:35pm UTC](https://forum.xojo.com/t/check-for-open-app/34786 "2016-12-04T18:35:05Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richard\_Summers](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_summers/32/477_2.png) [@Richard\_Summers](https://forum.xojo.com/u/Richard_Summers)\
**Post date:** [December 4, 2016, 6:35pm UTC](https://forum.xojo.com/t/check-for-open-app/34786/1 "2016-12-04T18:35:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![scott\_boss](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@scott\_boss](https://forum.xojo.com/u/scott_boss)\
**Post date:** [December 4, 2016, 6:44pm UTC](https://forum.xojo.com/t/check-for-open-app/34786/2 "2016-12-04T18:44:42Z")

</div>

[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?

---

<div class="post-metadata">

**Author:** ![Richard\_Summers](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_summers/32/477_2.png) [@Richard\_Summers](https://forum.xojo.com/u/Richard_Summers)\
**Post date:** [December 4, 2016, 6:46pm UTC](https://forum.xojo.com/t/check-for-open-app/34786/3 "2016-12-04T18:46:30Z")

</div>

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

Thanks.

---

<div class="post-metadata">

**Author:** ![scott\_boss](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@scott\_boss](https://forum.xojo.com/u/scott_boss)\
**Post date:** [December 4, 2016, 6:50pm UTC](https://forum.xojo.com/t/check-for-open-app/34786/4 "2016-12-04T18:50:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Richard\_Summers](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_summers/32/477_2.png) [@Richard\_Summers](https://forum.xojo.com/u/Richard_Summers)\
**Post date:** [December 4, 2016, 8:18pm UTC](https://forum.xojo.com/t/check-for-open-app/34786/5 "2016-12-04T20:18:14Z")

</div>

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

Thanks you very much.

---

<div class="post-metadata">

**Author:** ![scott\_boss](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@scott\_boss](https://forum.xojo.com/u/scott_boss)\
**Post date:** [December 4, 2016, 8:26pm UTC](https://forum.xojo.com/t/check-for-open-app/34786/6 "2016-12-04T20:26:46Z")

</div>

[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.

---

<div class="post-metadata">

**Author:** ![Richard\_Summers](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_summers/32/477_2.png) [@Richard\_Summers](https://forum.xojo.com/u/Richard_Summers)\
**Post date:** [December 4, 2016, 9:43pm UTC](https://forum.xojo.com/t/check-for-open-app/34786/7 "2016-12-04T21:43:05Z")

</div>

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 🙂

Thanks.

---

<div class="post-metadata">

**Author:** ![James\_Dooley](https://forum.xojo.com/user_avatar/forum.xojo.com/james_dooley/32/164_2.png) [@James\_Dooley](https://forum.xojo.com/u/James_Dooley)\
**Post date:** [December 4, 2016, 9:48pm UTC](https://forum.xojo.com/t/check-for-open-app/34786/8 "2016-12-04T21:48:18Z")

</div>

[http://documentation.xojo.com/index.php/Mutex](http://documentation.xojo.com/index.php/Mutex)

---

<div class="post-metadata">

**Author:** ![scott\_boss](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@scott\_boss](https://forum.xojo.com/u/scott_boss)\
**Post date:** [December 4, 2016, 10:02pm UTC](https://forum.xojo.com/t/check-for-open-app/34786/9 "2016-12-04T22:02:53Z")

</div>

> [@301491:@James Dooley](#):
>
> [http://documentation.xojo.com/index.php/Mutex](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.

---

<div class="post-metadata">

**Author:** ![Kem\_Tekinay](https://forum.xojo.com/user_avatar/forum.xojo.com/kem_tekinay/32/154_2.png) [@Kem\_Tekinay](https://forum.xojo.com/u/Kem_Tekinay)\
**Post date:** [December 4, 2016, 10:03pm UTC](https://forum.xojo.com/t/check-for-open-app/34786/10 "2016-12-04T22:03:58Z")

</div>

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:

```auto
/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.

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [December 4, 2016, 10:04pm UTC](https://forum.xojo.com/t/check-for-open-app/34786/11 "2016-12-04T22:04:30Z")

</div>

[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 🙂

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

```auto
/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.

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [December 4, 2016, 10:05pm UTC](https://forum.xojo.com/t/check-for-open-app/34786/12 "2016-12-04T22:05:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![scott\_boss](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/c5a1d2/32.png) [@scott\_boss](https://forum.xojo.com/u/scott_boss)\
**Post date:** [December 4, 2016, 10:09pm UTC](https://forum.xojo.com/t/check-for-open-app/34786/13 "2016-12-04T22:09:39Z")

</div>

> [@301499:@Norman Palardy](#):
>
> ps aux | grep -v grep | -i {applcation name} | wc -l

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [December 4, 2016, 10:12pm UTC](https://forum.xojo.com/t/check-for-open-app/34786/14 "2016-12-04T22:12:44Z")

</div>

whoops  
cut & paste 😛

---

<div class="post-metadata">

**Author:** ![Richard\_Summers](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_summers/32/477_2.png) [@Richard\_Summers](https://forum.xojo.com/u/Richard_Summers)\
**Post date:** [December 4, 2016, 10:13pm UTC](https://forum.xojo.com/t/check-for-open-app/34786/15 "2016-12-04T22:13:10Z")

</div>

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 🙂

Thank you everyone - I really appreciate your help!

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [December 4, 2016, 10:37pm UTC](https://forum.xojo.com/t/check-for-open-app/34786/16 "2016-12-04T22:37:51Z")

</div>

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

lsappinfo has a TON of options 🙂

---

<div class="post-metadata">

**Author:** ![Richard\_Summers](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_summers/32/477_2.png) [@Richard\_Summers](https://forum.xojo.com/u/Richard_Summers)\
**Post date:** [December 4, 2016, 10:51pm UTC](https://forum.xojo.com/t/check-for-open-app/34786/17 "2016-12-04T22:51:37Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [December 4, 2016, 11:03pm UTC](https://forum.xojo.com/t/check-for-open-app/34786/18 "2016-12-04T23:03:29Z")

</div>

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”

```auto
  // 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
```

---

<div class="post-metadata">

**Author:** ![Richard\_Summers](https://forum.xojo.com/user_avatar/forum.xojo.com/richard_summers/32/477_2.png) [@Richard\_Summers](https://forum.xojo.com/u/Richard_Summers)\
**Post date:** [December 4, 2016, 11:05pm UTC](https://forum.xojo.com/t/check-for-open-app/34786/19 "2016-12-04T23:05:59Z")

</div>

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??

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [December 4, 2016, 11:08pm UTC](https://forum.xojo.com/t/check-for-open-app/34786/20 "2016-12-04T23:08:33Z")

</div>

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

[Next page](https://forum.xojo.com/t/check-for-open-app/34786.md?page=2)
