如何在Mac OS X上将PHP Shell脚本作为Automator操作执行 [英] How do I execute a PHP shell script as an Automator action on Mac OS X

查看:105
本文介绍了如何在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操作执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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