我正在尝试启动TextEdit应用并将文件路径传递给它以打开,但不幸的是,它不起作用-TextEdit以常规模式启动。
这就是我想要做的:
let workspace = NSWorkspace.shared
let textEditUrl = URL(fileURLWithPath: "/Applications/TextEdit.app")
let file = "/path/to/file.whatever"
let configuration = [NSWorkspace.LaunchConfigurationKey.arguments : file]
// I also tried
// let configuration = [NSWorkspace.LaunchConfigurationKey.arguments :[file]]
do {
try workspace.launchApplication(
at: textEditUrl, options: [], configuration: configuration
)
} catch {
// Left blank
}
答案 0 :(得分:1)
有一个很好的旧NSTask
-在Swift中重命名为Process
。
Process.launchedProcess(launchPath: "/usr/bin/open", arguments: [
"-a",
"TextEdit",
"PATH_TO_YOUR_FILE"
])