Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sat Dec 15, 2018 3:15 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: How to Tell if an app is running on Mac OSX
PostPosted: Thu Mar 14, 2013 12:24 pm 
Offline

Joined: Sun Jan 28, 2007 2:38 pm
Posts: 231
Is it possible to seeif an app is running onmac OSX?

Pseduo Code

if isRunning (mail.app) then
//do something
end if


Top
 Profile  
Reply with quote  
 Post subject: Re: How to Tell if an app is running on Mac OSX
PostPosted: Thu Mar 14, 2013 12:34 pm 
Offline
User avatar

Joined: Mon Feb 05, 2007 5:21 pm
Posts: 600
Location: New York, NY
A few ways, but here is one:
dim sh as new Shell
sh.Execute "osascript -e 'running of app ""Mail.app""'"
dim isRunning as variant = sh.Result.Left( 4 ) = "True"

_________________
Kem Tekinay
MacTechnologies Consulting
http://www.mactechnologies.com/

Need to develop, test, and refine regular expressions? Try RegExRX.


Top
 Profile  
Reply with quote  
 Post subject: Re: How to Tell if an app is running on Mac OSX
PostPosted: Thu Mar 14, 2013 2:10 pm 
Offline
User avatar

Joined: Wed May 10, 2006 2:42 pm
Posts: 2985
Location: Germany
If you use our MBS Plugins, you can use the ProcessMBS class or the NSRunningApplicationMBS class.

Greetings
Christian

_________________
See you in Orlando, Florida for Real World 2013
More details and registration here:
http://www.realsoftware.com/community/realworld.php


Top
 Profile  
Reply with quote  
 Post subject: Re: How to Tell if an app is running on Mac OSX
PostPosted: Thu Mar 14, 2013 4:20 pm 
Offline

Joined: Sun Jan 28, 2007 2:38 pm
Posts: 231
Thanks guys:

I sloved it like this:

Function mac_IsAppRunning(myAppName as string) As Boolean

Dim MyShell as new Shell
MyShell.Execute ("osascript -e 'tell application "+chr(34)+"System Events"+chr(34)+" to get name of (processes where background only is false)'")

Dim output As String = MyShell.ReadAll

dim targetspot as integer
targetspot=InStr (output,myAppName)

if targetspot>0 then
return True
else
return false
end if
End Function


Top
 Profile  
Reply with quote  
 Post subject: Re: How to Tell if an app is running on Mac OSX
PostPosted: Thu Mar 14, 2013 4:35 pm 
Offline
User avatar

Joined: Mon Feb 05, 2007 5:21 pm
Posts: 600
Location: New York, NY
The drawback to doing it that way is that you could get an incorrect match. For example, if you have "Mail Helper" running and try to find out if "Mail" is running, you will get the wrong answer.

I'm not sure why you preferred this to my one-line solution, but assuming there is a reason, you should at least split the output into lines and check each line, maybe like this:
Function mac_IsAppRunning(myAppName as string) As Boolean

Dim MyShell as new Shell
MyShell.Execute ("osascript -e 'tell application "+chr(34)+"System Events"+chr(34)+" to get name of (processes where background only is false)'")

Dim output As String = MyShell.ReadAll
dim apps() as string = output.Split( ", " )
return apps.IndexOf( myAppName ) <> -1
End Function

_________________
Kem Tekinay
MacTechnologies Consulting
http://www.mactechnologies.com/

Need to develop, test, and refine regular expressions? Try RegExRX.


Top
 Profile  
Reply with quote  
 Post subject: Re: How to Tell if an app is running on Mac OSX
PostPosted: Fri Mar 15, 2013 12:07 am 
Offline

Joined: Sun Jan 28, 2007 2:38 pm
Posts: 231
I simply worked out the other one, flaws and all, on an airplane as you were posting your answer.

Your solution is certainly more elegant


Top
 Profile  
Reply with quote  
 Post subject: Re: How to Tell if an app is running on Mac OSX
PostPosted: Fri Mar 15, 2013 8:00 am 
Offline

Joined: Sun Jan 28, 2007 2:38 pm
Posts: 231
All of the suggested solutions show the apps running under the main user.

How does one get a list of the apps running as root? (like a stand alone web app!)


Top
 Profile  
Reply with quote  
 Post subject: Re: How to Tell if an app is running on Mac OSX
PostPosted: Fri Mar 15, 2013 8:54 am 
Offline
User avatar

Joined: Tue Jan 04, 2011 3:02 am
Posts: 1236
Location: Jönköping, Sweden
JohnV wrote:
All of the suggested solutions show the apps running under the main user.

How does one get a list of the apps running as root? (like a stand alone web app!)

How about running:
ps aux | less

in a shell and look for your app in there? :)
Don't know it it works on other than Linux though :/

_________________
Image http://www.linkedin.com/in/albinkiland
Dev. iMac 27" + 2x22" LG (2.8GHz Intel Core i7, 12GB RAM, 120GB SSD) OS X 10.8
Xojo Pro 2013r1


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group