Re: PHP and Applescript
Re: PHP and Applescript
- Subject: Re: PHP and Applescript
- From: Axel Luttgens <email@hidden>
- Date: Sat, 9 Feb 2008 18:21:50 +0100
Le 9 févr. 08 à 16:06, Grace Finn a écrit :
How do I write a PHP to open an Applescript from a web page? I am
not that familiar with PHP, but I have gotten a test hello world to
work.
Hello Grace,
I guess your test hello world was a PHP file along those lines:
<?php
echo "hello world";
?>
Now I just need a detailed way to get PHP to call an Applescript. I
do not need anything returned to the user 0 I only need an
Applescript execution. Is this possible?
Yes, of course. :-)
(with all the usual caveats about security)
For example, save this AppleScript:
beep 3
as file "test.scpt" into your "Sites" folder (i.e. ~/Sites/test.scpt)
and this PHP script:
<?php
exec('/usr/bin/osascript test.scpt');
?>
as file "test.php" into the same folder.
Now, opening "http://127.0.0.1/~gracefinn/test.php" in your web
browser should yield three beeps.
(note that the beep action isn't the best choice, even if it works;
see below)
Another example, should you nevertheless need some return from the
AppleScript's execution.
The test.scpt script:
"hello from AppleScript"
and the test.php file:
<?php
echo exec('/usr/bin/osascript test.scpt');
?>
As it appears from the man page for osascript(1), it would even be
possible to pass arguments to the AppleScript from PHP.
Now, it should be noted that the AppleScript runs under the identity
of the web server, that is as user "_www".
This means that the AppleScript shouldn't involve any user interaction.
The same way, should it need to read files, one must ensure that those
files are readable by that user.
And so on.
More generally, it could even appear that running an AppleScript isn't
needed at all: either PHP itself or some shell commands invoked from
PHP might fulfill your needs, without an additional layer.
HTH,
Axel _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden