1

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.

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

Hi there I am sorry couldn’t understand your point. Do you need more guidance on the subject?
Sorry, I don't remember, but if you wish, I will try to answer the question again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.