Reputation: 41
I'm trying to run AppleScript in PHP. The following is my code:
<?php
echo "Hello World!";
shell_exec('osascript -e \'tell app "Finder" to make new Finder window\'');
shell_exec('osascript -e \'display dialog "hello" \'');
shell_exec('osascript ~/openExcel.scpt');
echo "DONE";
?>
When I run each command individually in terminal, I can get the expected result. However, when I open this .php file in server as a webpage, I can only get "Hello World!DONE"
. The middle part (3 exec
commands) have no output result at all. I don't understand.
Upvotes: 1
Views: 1136
Reputation: 307
Create an AppleScript Application and save it with the app extension, then link from the PHP page. I use it on some projects in localhost, it works.
Upvotes: 1
Reputation: 3542
As far as I know you can't execute AppleScript from a webserver for security reasons. The problem is that AppleEvents can only be send through the window server by the user that's only currently logged in as the windowserver user (console user) or as root. By default apache will run as _www as it's shells and _www user can't run osascript on the command line.
The workaround is running the shell command as console user or as root.
Upvotes: 2