PHP System/exec command and OSAScript Command

Hi There Everyone!

I am working on a project where I was hoping to using the PHP system or exec commands to run an applescript on a mac os x server system using osascript. Basically, hitting a link should advance a keynote presentation. But, I’ve hit a snag

Below is an elaborate version of the PHP code I was using the try to call the script. I started with just the exec or system commands but this gave me some more error checking.

If I run the script locally by any means, the script works just fine.

But, if I try to leverage PHP to call the applescript, no action is taken.

Here is the error I’ve been getting from my PHP code below.

“array ( ‘stdout’ => ‘’, ‘stderr’ => '/Users/Shared/ScriptsFolder/test17.scpt:34:39: script error: Expected end of line but found identifier. (-2741) ', ‘return’ => 1, )”

But, running the same script from script editor or the terminal produces no such error. Is it because the script is being run as the _www user? Might there be a way around that? I’m not wedded to PHP but I am wedded to leveraging a web page at this point.

Thanks in advance for any assistance whatsoever.

--------------------------------------code----------------------------

<?php function my_exec($cmd, $input='') {$proc=proc_open($cmd, array(0=>array('pipe', 'r'), 1=>array('pipe', 'w'), 2=>array('pipe', 'w')), $pipes); fwrite($pipes[0], $input);fclose($pipes[0]); $stdout=stream_get_contents($pipes[1]);fclose($pipes[1]); $stderr=stream_get_contents($pipes[2]);fclose($pipes[2]); $rtn=proc_close($proc); return array('stdout'=>$stdout, 'stderr'=>$stderr, 'return'=>$rtn ); } var_export(my_exec('osascript /Users/Shared/ScriptsFolder/test17.scpt')); ?>

tell application "Keynote"
	show slide 17 of slideshow 1
end tell

Not to discourage your PHP efforts (and I can’t help at all with respect), but here’s something you may be able to work with:

‘Webpage Helper’

http://applescript.tv/linktrigger/

Good Luck

Peter B.


Hello.

You will find a variety of ways to accomplish this if you search the AppleScript Users Mailing list this month.

Thanks folks! I’ll take a look and let you know of my results.

Like Peter, I don’t want to discourage your PHP efforts. (Just yesterday, I was running a Python script via PHP.) However, you might also want to check out the recently released Apache-Apple Event Bridge.

I just tried to run your AppleScript via Script Editor while Keynote wasn’t running. Keynote wasn’t responding; I forced it to quit, after which Script Editor returned that same error message, while highlighting the word slide.

Offhand, I would guess that the script is having difficulties communicating with Keynote.

Edit: I tried running your PHP script and I received this:

array ( 'stdout' => '', 'stderr' => '/Users/bruce/keynote.scpt: execution error: An error of type -10810 has occurred. (-10810) ', 'return' => 1, )

With a Keynote file open, the AppleScript does work normally in Script Editor and in Terminal (via osascript).