NSWorkspaceMBS.launchApplication problem with Apple apps

There is no need for the application path as Greg already mentioned.
Based on this discussion you can just use the CFBundleIdentifier:

Public Function LaunchAppFromBundleID(bundID as String) As Boolean
  Declare Function NSClassFromString Lib "Foundation" ( className As CFStringRef ) As Ptr
  Declare Function sharedWorkspace Lib "AppKit" Selector "sharedWorkspace" ( ref As Ptr ) As Ptr
  Declare Function URLForApplicationWithBundleIdentifier Lib "AppKit" Selector "URLForApplicationWithBundleIdentifier:" ( NSWorkspace As Ptr , bundleIdentifier As CFStringRef ) As Ptr
  Declare Function absoluteString Lib "AppKit" Selector "absoluteString" ( NSURLRef As Ptr ) As CFStringRef
  Declare Function launchApp Lib "AppKit" Selector "launchAppWithBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifier:"_
  ( NSWorkspaceRef As Ptr, bundleIdentifier As CFStringRef, options As Ptr, descriptor As Ptr, identifier As Integer ) As Boolean
  
  Dim URLRef As Ptr = URLForApplicationWithBundleIdentifier( sharedWorkspace( NSClassFromString( "NSWorkspace" ) ), bundID)
  If URLRef <> Nil Then
    Dim f As folderitem = GetFolderItem( absoluteString( URLRef ), folderItem.pathTypeURL )
    If f <> Nil And f.exists Then
      Call launchApp( sharedWorkspace( NSClassFromString( "NSWorkspace" ) ), "com.apple.TextEdit", Nil, Nil, 0 )
      Return True
    End
  End
  Return False  
End Function

and call it via

Call LaunchAppFromBundleID("com.apple.TextEdit")

No need for a Plugin here.

4 Likes