gpt4 book ai didi

swift (macOS) : Launch TextEdit with file

转载 作者:行者123 更新时间:2023-11-28 05:41:24 24 4
gpt4 key购买 nike

我正在尝试启动一个 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
}

最佳答案

有一个很好的旧 NSTask - 在 Swift 中重命名为 Process

Process.launchedProcess(launchPath: "/usr/bin/open", arguments: [
"-a",
"TextEdit",
"PATH_TO_YOUR_FILE"
])

关于 swift (macOS) : Launch TextEdit with file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56594013/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com