0

I'll open Safari, other system apps and third-party apps with codes like:

let task = NSTask()
task.launchPath = "/usr/bin/open"
task.arguments = ["Safari"]
task.launch()

will it be rejected by MAS review?

I know there is recommended way by Apple which leverages Apple Script and com.apple.security.scripting-targets. But it's so weak now.

Thanks

mahal tertin
  • 3,239
  • 24
  • 41
guoleii
  • 496
  • 6
  • 15

2 Answers2

1

Actually the recommended way to launch applications is

NSWorkspace.sharedWorkspace().launchApplication("Safari")

or – more sophisticated

let sharedWorkspace = NSWorkspace.sharedWorkspace()
if let safariURL = sharedWorkspace.URLForApplicationWithBundleIdentifier("com.apple.safari") {
    try? sharedWorkspace.launchApplicationAtURL(safariURL, options: NSWorkspaceLaunchOptions(), configuration: [:])
}
vadian
  • 274,689
  • 30
  • 353
  • 361
  • thanks for your answer. where can i find configuration/launch arguments for applications like TextEdit, Safari? I searched but got nothing helpful. – guoleii Jan 05 '16 at 06:54
0

Even more sophisticated you may use launch services LSOpenFromURLSpec as described in the reference. Pass launchs options in the specs array.

LSLaunchURLSpec inLaunchSpec;

inLaunchSpec.appURL = (__bridge CFURLRef) urlOfAppToOpen;
inLaunchSpec.itemURLs =  (__bridge CFArrayRef) (arrayOfurlsOfFilesToOpenWithApp);
inLaunchSpec.passThruParams = NULL;
inLaunchSpec.launchFlags = kLSLaunchDefaults;
inLaunchSpec.asyncRefCon = NULL;

CFURLRef outLaunchedURL;
OSStatus diditOpen = LSOpenFromURLSpec (
                                        &inLaunchSpec,
                                        &outLaunchedURL
                                        );
mahal tertin
  • 3,239
  • 24
  • 41