Determine if external app is running

Is there a way to determine if OSX is currently running a specific app?

something like

If isRunning("Xcode.app")  then msgbox "XCode is currently running."

[quote=181250:@Dave S]Is there a way to determine if OSX is currently running a specific app?

something like

If isRunning("Xcode.app") then msgbox "XCode is currently running." [/quote]

Shell to ps Aux and parse the result.

https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/ps.1.html

Haven’t tried it myself but I’d checkout MacOSLib NSWorkspace.RunningApplications.

make an AppleScript (name it AppRunning)

on run {myApp}
	if application myApp is running then
		display dialog myApp & " is running"
	end if
end run

drop it to yourXojo Project

  dim myApp as string = // your App Name
  AppRunning(myApp)

This lists the PID, but not the app names

that works, but how to return a result BACK to Xojo (not just display it)

will look at that

Regarding AppleScript: as far as I remember you have to assign the result to a variable (I’m only using MBS for this). You could even do an AppleScript in the shell and get the result from there.

change Applesript to

on run {myApp}
	if application myApp is running then
		return true
	else
		return false
	end if
end run

make a property AppIsRunning (Boolean)

Xojo

  dim myApp as string = // App Name
  if AppRunning(myApp) = "true" then
    AppIsRunning = true
  elseif AppRunning(myApp) = "false" then
    AppIsRunning = false
  end if
  MsgBox str(AppIsRunning)

I named the AppleScript “Check_Running”

and reduced your XOJO code to

Function Check_if_Running(app_name) as boolean
    return (check_running(app_name)="true")
End Function

and works just fine… Thanks