【发布时间】:2017-06-11 10:05:51
【问题描述】:
我正在尝试通过运行终端命令在 Finder 中显示隐藏文件。问题是看起来defaults write com.apple.finder AppleShowAllFiles TRUE 有多个启动路径。当我在终端中运行which 命令,然后是我尝试运行的命令时,它给了我三个路径:/usr/bin/defaults、/usr/bin/write 和/usr/bin/TRUE。我不能将这三个都设置为命令的启动路径,因为.launchPath 不接受数组。
如何运行此命令?
edit:问题是我没有将参数分成单独的字符串。此代码有效:
@IBAction func showAllFiles(_ sender: NSMenuItem) {
let task = Process()
task.launchPath = "/usr/bin/defaults"
task.arguments = ["write", "com.apple.finder", "AppleShowAllFiles", "TRUE"]
task.launch()
task.waitUntilExit()
}
【问题讨论】:
-
顺便说一句,XtraFinder 让您可以在查找工具栏中添加一个按钮,让您可以显示/隐藏隐藏文件
-
你能添加你如何创建任务的 swift 代码吗?否则它看起来与 swift 无关