PHP shell Automator MacOS Monterey 中的脚本不再有效

PHP shell script in Automator MacOS Monterey no longer works

MacOS Monterey 似乎仅在 Automator 中支持 PHP。

您可以 运行 PHP 从终端无错误(如果通过 Brew 安装)但是 运行ning PHP 来自 Automator 的脚本 “运行 Shell 脚本” 给出错误

php: command not found

在终端中,运行宁

which php

结果 /usr/local/bin/php

有趣的是,较新的快捷方式应用程序支持 PHP 脚本。有什么想法可以让 Automator 再次与 PHP 一起工作吗?

发生这种情况是因为您到 PHP 的路径在 /user/local/bin 中,并且它不再是 Automator 使用的 PATH 的一部分,就像它看起来的那样。

在未修改的 Automator "运行 Shell 脚本" 步骤中,PATH 变量包含

/usr/bin:/bin:/usr/sbin:/sbin

因此,修复它的简单方法是将 /usr/local/bin 添加到 "运行 Shell 脚本中的 PATH".
为此,您只需在上述任务中添加第一行,其中包括:

PATH="/usr/local/bin:$PATH"

从那时起,Automator 将能够像以前一样正确地找到 PHP 二进制文件。


有关什么是 PATH 变量及其在 Linux 和 Unix 中的含义的更多信息(Mac OS 是一个 Unix-like 发行版)可以找到here.