使用多个启动路径运行终端命令 swfit [英] Use multiple launch paths to run terminal command swfit

查看:36
本文介绍了使用多个启动路径运行终端命令 swfit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过运行终端命令在 Finder 中显示隐藏文件.问题是看起来 defaults write com.apple.finder AppleShowAllFiles TRUE 有多个启动路径.当我在终端中运行 which 命令后跟我试图运行的命令时,它给了我三个路径:/usr/bin/defaults/usr/bin/write/usr/bin/TRUE.我无法将所有三个都设置为命令的启动路径,因为 .launchPath 不接受数组.

I'm trying show hidden files in Finder by running a terminal command. The problem is it looks like defaults write com.apple.finder AppleShowAllFiles TRUE has multiple launch paths. When I run the which command in terminal followed by the command I'm trying to run, it gives me three paths: /usr/bin/defaults, /usr/bin/write, and /usr/bin/TRUE. I can't set all three as launch paths for the command because .launchPath doesn't accept an array.

我怎样才能运行这个命令?

How can I run this command?

问题是我没有将参数分成单独的字符串.此代码有效:

edit: The problem was I wasn't separating the arguments into separate strings. This code works:

@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()
}

推荐答案

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

You're looking for /usr/bin/defaults. The reason you're getting this output is because the following command:

which defaults write com.apple.finder AppleShowAllFiles TRUE

就像在做:

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

打印:

/usr/bin/defaults

/usr/bin/defaults

/usr/bin/write

/usr/bin/write

(什么都没有)

(什么都没有)

(什么都没有)

/usr/bin/TRUE

/usr/bin/TRUE

这篇关于使用多个启动路径运行终端命令 swfit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆