Using AppleScript with PHP (& Vice-Versa)
AppleScript and PHP can be used together in various ways.
You can run AppleScript from PHP using backtick quoting and the osascript command. Backtick quoting is a shortcut in PHP for the shell_exec() command which runs shell commands – any shell command not just AppleScript.
e.g.
You can use this method to run a fragment of AppleScript code.
osascript -e 'some AppleScript';
Or this to run an entire script (in a separate file).
osascript ascript.scpt;
Conversely you can run Perl scripts from AppleScript.
You can run fragments or entire scripts using the do shell script “php…” command syntax.
There would appear to be a few minor limitations regarding the combining of AppleScript and PHP. AppleScripts run from the command line with osascript can’t to interact with the AppleScript GUI components (dialogues etc.). To take advantage of these features we need to bundle the script as an application.
Resources
Examples – runphp.app + hello.php, slideshow.php + slideshow.scpt, speak.php & uc.scpt (zip, 8kb)