How do I execute a PHP shell script as an Automator action on Mac OS X(如何在 Mac OS X 上执行 PHP shell 脚本作为 Automator 操作)
问题描述
我被 Automator.app 在 Mac OS X Snow Leopard 中创建上下文服务的能力所吸引.我想创建一些键盘可访问的快捷方式来通过调用 shell 脚本来操作文本片段.但是,Automator 只建议使用 bash、Perl、Python 和 Ruby(以及其他)来实现这一点.但是,由于 PHP 也随 Mac OS 一起提供(老实说,它是我唯一完全掌握的脚本语言),我想知道为什么我不能运行 PHP shell 脚本.
I'm tempted by Automator.app's ability to create contextual services in Mac OS X Snow Leopard. I would like to create some keyboard accessible shortcuts to manipulate text snippets by calling a shell script. However, Automator only suggests bash, Perl, Python and Ruby (among others) to allow this. But, since PHP also ships with Mac OS (and, to be honest, it's the only scripting language I fully master), I wonder why I can't run a PHP shell script.
推荐答案
上面dbr的解决方案很好,但是我发现它对我不起作用,可能是由于后来更改了shell、php或OS版本(我使用的是 OS X 10.8).经过大量的挠头,我发现答案是引用heredoc标记.
dbr's solution above is excellent, but I found that it didn't work for me, perhaps due to a later change in the shell, php, or OS version (I'm using OS X 10.8). After a lot of head-scratching I found that the answer is to quote the heredoc marker.
一个有用的补充是使用适当的语法将参数传递给 php 脚本.将所有这些放在一起,我正在使用:
A useful addition is to use the appropriate syntax to pass the arguments through to the php script. Putting all that together, I'm using:
php -- "$@" <<'EOF'
<?php
print_r( $argv );
?>
EOF
这篇关于如何在 Mac OS X 上执行 PHP shell 脚本作为 Automator 操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Mac OS X 上执行 PHP shell 脚本作为 Automator 操作


基础教程推荐
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- PHP 守护进程/worker 环境 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01