MacOS: URLForApplicationWithBundleIdentifier

Share your advanced PureBasic knowledge/code with the community.
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

MacOS: URLForApplicationWithBundleIdentifier

Post by mk-soft »

In case anyone needs it :wink:

Code: Select all

;-TOP by mk-soft, v1.01.0, 11.03.2023

Procedure.s URLForApplicationWithBundleIdentifier(Indentifier.s, Full = #False)
  Protected NSPool = CocoaMessage(0, 0, "NSAutoreleasePool new")
  Protected NSWorkshare = CocoaMessage(0, 0, "NSWorkspace sharedWorkspace")
  Protected NSUrl, NSPathString, Path.s
  
  NSUrl = CocoaMessage(0, NSWorkshare, "URLForApplicationWithBundleIdentifier:$", @Indentifier)
  NSPathString = CocoaMessage(0, NSURL, "path")
  If NSPathString
    Path = PeekS(CocoaMessage(0, NSPathString, "UTF8String"), -1, #PB_UTF8)
  EndIf
  If Full
    If GetExtensionPart(path) = "app"
      Path = path + "/Contents/MacOS/" + GetFilePart(path, #PB_FileSystem_NoExtension)
    EndIf
  EndIf
  CocoaMessage(0, NSPool, "release")
  ProcedureReturn Path
EndProcedure

terminalApp.s = URLForApplicationWithBundleIdentifier("com.apple.Terminal", #True)
Debug terminalApp
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive