【问题标题】:Use multiple launch paths to run terminal command swfit使用多个启动路径快速运行终端命令
【发布时间】: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 无关

标签: swift terminal swift3


【解决方案1】:

您正在寻找/usr/bin/defaults。您获得此输出的原因是因为以下命令:

which defaults write com.apple.finder AppleShowAllFiles TRUE

就像在做:

which defaults
which write
which com.apple.finder
which AppleShowAllFiles
which TRUE

哪个打印:

/usr/bin/默认值

/usr/bin/写

(什么都没有)

(什么都没有)

(什么都没有)

/usr/bin/真

【讨论】:

  • 很高兴知道。那么如何在 Swift 中运行 defaults write com.apple.finder AppleShowAllFiles TRUE 呢?
猜你喜欢
  • 1970-01-01
  • 2018-01-18
  • 1970-01-01
  • 1970-01-01
  • 2016-10-06
  • 2017-08-18
  • 2020-12-03
  • 2018-12-12
  • 2012-06-10
相关资源
最近更新 更多