How do I execute a PHP shell script as an Automator action on Mac OS X

Roel picture Roel · Sep 9, 2009 · Viewed 9.5k times · Source

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.

Answer

rogeriopvl picture rogeriopvl · Sep 9, 2009

This is just a hack, but how about creating a python, or ruby or perl or bash script that calls php command-line interpreter with the php script you want to execute?

For instance in bash would be as simple as this:

#!/bin/bash   
php myscript.php

Now save it, give it permission for execution:

chmod +x my_bash_script.sh

And voilá. Automator can now run the bash script, which calls the php script.