使用 NSWorkspace 不起作用的参数启动应用程序

问题描述 投票:0回答:1

我想用参数打开 FileZilla(ftp 应用程序)。

它正在与 NSTask(又名进程)一起使用:

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

它不适用于 NSWorkspace

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

不工作我的意思是,FileZilla 启动,但参数没有被忽略。

API 看起来很简单,但我不知道我在这里做错了什么。

我想使用 NSWorkspace 的原因是 NSTask 应用程序不会在前台启动。

swift macos cocoa nstask nsworkspace
1个回答
0
投票

我正在使用

launchAgent
来运行运行我的应用程序的脚本,我发现如果我们需要传递配置,我们需要在执行 open 函数后稍等一下:

NSWorkspace.shared.open(appURL, configuration: configuration)
Thread.sleep(forTimeInterval: 1)
© www.soinside.com 2019 - 2024. All rights reserved.