Please add better launchApplication(withBundleIdentifier:...) to NSWorkspace

Originator:automate.mantasystems
Number:rdar://29159280 Date Originated:2016-11-08
Status:Open Resolved:
Product:macOS SDK Product Version:10.12
Classification:Enhancement Reproducible:Always
 
Summary:
NSWorkspace currently provides the following methods for launching apps by file URL or bundle identifier:

launchApplication(at url: URL, options: NSWorkspaceLaunchOptions = [], configuration: [String : Any]) throws -> NSRunningApplication

launchApplication(withBundleIdentifier bundleIdentifier: String, options: NSWorkspaceLaunchOptions = [], additionalEventParamDescriptor descriptor: NSAppleEventDescriptor?, launchIdentifier identifier: AutoreleasingUnsafeMutablePointer<NSNumber?>?) -> Bool

The first works well:

- it accepts a first AppleEvent via its configuration parameter, 

- throws an error on failure, and 

- returns an NSRunningApplication instance identifying the [newly launched] process on success. 

However, it requires the path to the app bundle be known, so cannot be used in sandboxed apps that restrict file system information and access.

In principle, launchApplication(withBundleIdentifier:...) provides a sandbox-friendly alternative to launchApplication(at:...); however it is seriously deficient in several respects: 

- it does not take a configuration parameter, 

- its additionalEventParamDescriptor is useless for specifying a first AppleEvent (or anything useful as far as I can tell), 

- it does not provide any error information beyond a Boolean NO to indicate failure, and 

- it does not return an NSRunningApplication instance that identifies the process it _actually_ launched, which in turn means there's no reliable way to get identify that process. (A subsequent call to NSRunningApplication.runningApplications(withBundleIdentifier:String) provides a partial workaround, but _only_ if a single match is found; if multiple matches exist then there is no way to determine which was created by the launchApplication call.)

To remedy these problems, please add a launchApplication(withBundleIdentifier:...) method to NSWorkspace that takes the same options and configurations arguments as launchApplication(at:...), and throws the same NSError returns the same NSRunningApplication result on failure/success:

launchApplication(withBundleIdentifier bundleID: String, options: NSWorkspaceLaunchOptions = [], configuration: [String : Any]) throws -> NSRunningApplication

Comments

For the record, you can use LaunchServices to get the URL for an application by bundle identifier. Check out the LSCopyApplicationURLsForBundleIdentifier() function.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!