Daniel
Daniel

Reputation: 1057

Launch application with arguments with NSWorkspace not working

I would like to open FileZilla (ftp application) with an argument.

It is working with NSTask (aka. Process):

let process:Process = Process()
process.launchPath = appURL.path
process.arguments = ["ftp://1.2.3.4"]
process.launch()

It is not working with NSWorkspace:

try! NSWorkspace.shared().launchApplication(
   at: appURL,
   options: .default,
   configuration: [NSWorkspaceLaunchConfigurationArguments:["ftp://1.2.3.4"]]
)

With not working I mean, that FileZilla launches, but the argument is not passed over.

The API seems simple, but I can not figure out what I am doing wrong here.

The reason why I want to use NSWorkspace is, that NSTask the application will not launch in foreground.

Upvotes: 6

Views: 3656

Answers (1)

Hadi
Hadi

Reputation: 1373

I am using a launchAgent to run a script that runs my app, I found that if we need to pass a configuration, we need to wait a little bit after executing the open function:

NSWorkspace.shared.open(appURL, configuration: configuration)
Thread.sleep(forTimeInterval: 1)

Upvotes: 0

Related Questions