jeffrey.d.m
jeffrey.d.m

Reputation: 867

Swift not applying flags to application being opened (Flutter native code)

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.

  1. Is there a better way of opening the app or some configuration that will respect the arguments passed to it?
  2. If not:
    • What is the difference between using open, and calling the executable directly?
    • What potential issues can arise from running the executable directly, instead of opening the app normally?

Upvotes: 0

Views: 27

Answers (0)

Related Questions