Code: Select all
;-TOP
; Comment : IsRunning
; Author : mk-soft
; Version : v1.01
; Date : 05/11/2014
Procedure IsRunning(App.s)
Protected RunningApps = CocoaMessage(0, CocoaMessage(0, 0, "NSWorkspace sharedWorkspace"), "runningApplications")
Protected RunningAppsCount = CocoaMessage(0, RunningApps, "count")
Protected RunningApp, AppName.s
Protected i, count
While i < RunningAppsCount
RunningApp = CocoaMessage(0, RunningApps, "objectAtIndex:", i)
AppName.s = PeekS(CocoaMessage(0, CocoaMessage(0, RunningApp, "localizedName"), "UTF8String"), -1, #PB_UTF8)
If AppName = App
count + 1
EndIf
i + 1
Wend
If count > 1
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
; Test
CompilerIf #PB_Compiler_IsMainFile
If IsRunning("MyApp")
End
EndIf
If OpenWindow(0, #PB_Ignore, #PB_Ignore, 300, 100, "MyApp")
Repeat
event = WaitWindowEvent()
Until event = #PB_Event_CloseWindow
EndIf
CompilerEndIf
