Re: PHP and Applescript
Re: PHP and Applescript
- Subject: Re: PHP and Applescript
- From: Brian Johnson <email@hidden>
- Date: Sat, 9 Feb 2008 10:27:09 -0800 (PST)
This is going to say pretty much the same thing that Axel said, but note
quite.
PHP is cross-platform, so it doesn't know about AppleEvents, per se.
However, it has an "exec" function for running applications on the host,
so you need a command-line means of running your script, like "osascript".
Assuming that by "open an applescript" you mean "run", the answer goes
like this:
Given the existence of script
"hello.scpt" with the single line
return "Hi There"
The Terminal command to run this is (assuming you've CD'd to the correct
directory)
osascript hello.scpt
so the php script might look like
<?php
echo exec("osascript /users/you/myscripts/hello.scpt");
?>
Because PHP generally executes as www rather than as a 'normal' user,
you'll need to provide the full path (no "~"). Note, as well, all the
justifiable cautions at php.net about allowing user input to reach "exec".
Having said all that; since I don't do this kind of thing from PHP, I
built a test page and script to make sure the above was right .... and it
doesn't work (quite silently).
Axel, did you test yours? I ask because this all finally reminded me
(doh!) of a fundamental truth: that AppleEvents rely on the user's
WindowManager(?) process, which is only present for logged-in ('normal')
users, which is why I wrote "peacePipe" back in 2005 (sigh). peacePipe is
a bit of a kludge, but it works for applescript CGIs and can be used to
have (mostly cron) shell scripts launch applescripts. I haven't done it
yet, but a shell 'glue script' using peacePipe to run the AS might be
necessary between PHP exec and AS. (Emanuel, that's your cue to tell us
how Satimage can do this...)
I'll try to get back to this later today, but want to get this off (as
refutation bait) in the mean time.
-b.johnson, dept of architecture, university of washington, seattle
On Sat, 9 Feb 2008, Grace Finn wrote:
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. 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?
_______________________________________________
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