如何从 Applescript 调用 brew
How can I call brew from an Applescript
我正在尝试创建一个脚本来检查 Homebrew 是否安装在任何给定的 mac 上,以防它是否安装了特定的公式。我有检查是否安装了 brew 的部分,但是当我尝试 运行 brew list 以查看安装了哪些软件包时,我得到 "Command not found" 即使我可以 运行 终端中的命令美好的。我正在使用:
do shell script "brew list"
有没有其他方法可以 运行 Applescript 中的 brew 命令?
最好直接调用命令,否则 AppleScript 可能找不到返回 command not found
的正确路径 — 为此,您需要查看 brew
命令在 Terminal
:
$ which brew
/usr/local/bin/brew
基于此你应该能够做到:
do shell script "/usr/local/bin/brew list"
如果命令后有多个参数,请使用 -c
选项:
do shell script "/usr/local/bin/brew -c list <package>"
If the -c option is present, then commands are read from
string. If there are arguments after the string, they are
assigned to the positional parameters, starting with [=18=].
如果您想要一个完整的方法来找出路径,您可以执行以下操作:
set brewPath to do shell script "/usr/bin/which brew | awk '{print [=13=]}'" as string
set brewList to do shell script "" & brewPath & " list" as string
*注意:我还没有测试过,所以可能需要一些调整。
我正在尝试创建一个脚本来检查 Homebrew 是否安装在任何给定的 mac 上,以防它是否安装了特定的公式。我有检查是否安装了 brew 的部分,但是当我尝试 运行 brew list 以查看安装了哪些软件包时,我得到 "Command not found" 即使我可以 运行 终端中的命令美好的。我正在使用:
do shell script "brew list"
有没有其他方法可以 运行 Applescript 中的 brew 命令?
最好直接调用命令,否则 AppleScript 可能找不到返回 command not found
的正确路径 — 为此,您需要查看 brew
命令在 Terminal
:
$ which brew
/usr/local/bin/brew
基于此你应该能够做到:
do shell script "/usr/local/bin/brew list"
如果命令后有多个参数,请使用 -c
选项:
do shell script "/usr/local/bin/brew -c list <package>"
If the -c option is present, then commands are read from string. If there are arguments after the string, they are assigned to the positional parameters, starting with [=18=].
如果您想要一个完整的方法来找出路径,您可以执行以下操作:
set brewPath to do shell script "/usr/bin/which brew | awk '{print [=13=]}'" as string
set brewList to do shell script "" & brewPath & " list" as string
*注意:我还没有测试过,所以可能需要一些调整。