Reputation: 867
I have a Flutter plugin which needs to launch an app, but it must include a specific flag which changes application behavior. However, this is not working from within my native Swift macOS code, unless I launch the app executable itself.
Here is a working command, when run from my terminal: open /Applications/The\ App.app --args -r
. This is basically what I am trying to accomplish.
Here is the working code I have, and what I tried:
let task = Process()
task.launchPath = "/Applications/The App.app/Contents/MacOS/The App"
task.arguments = ["-r"]
task.launch()
task.waitUntilExit()
// What was attempted, and did not work:
// task.launchPath = "/bin/zsh"
// task.arguments = ["-c", "open /Applications/The\\ App.app --args -r"]
// task.launchPath = "/usr/bin/open"
// task.arguments = ["/Applications/The App.app", "--args", "-r"]
// task.arguments = ["/Applications/The App.app", "-r"]
// task.arguments = ["-a", "/Applications/The App.app", "--args", "-r"]
// let configuration = NSWorkspace.OpenConfiguration()
// configuration.arguments = ["-r"]
// NSWorkspace.shared.openApplication(
// at: URL(fileURLWithPath: "/Applications/The App.app"),
// configuration: configuration)
// Process.run(URL(fileURLWithPath: "/Applications/The App.app"), arguments: ["-r"])
The app is running in App Sandbox, but removing this did not change the behavior either.
open
, and calling the executable directly?Upvotes: 0
Views: 27