 |
 |
Calling AppleScript from Perl CGI
|
 |
|
 |
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
The Perl script cannot seem to run the AppleScript when run as a CGI. When run from the command line, the Perl script runs the AppleScript fine.
I'm using the Perl "system" command and the arguments to "system" that I've tried are:
"/usr/bin/open <path to AppleScript>"
and
"/usr/bin/osascript <path to AppleScript>"
In both cases, the perl script works from the command line, but fails when run as a CGI.
(yes, I'm running it as the same user on the CLI as the web server runs as... "www").
(Last edited by Brass; Aug 29, 2002 at 11:27 PM.
)
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Sep 2000
Location: Springfield, MA
Status:
Offline
|
|
You aren't doing anything wrong. It's a feature, not a bug. I touched upon this problem recently in this thread.
The problem is that, as a security feature I believe, programs that aren't descendants of the Window Manager (apache, ssh, ftp.... eg the stuff that is still running after you log out) can't communicate with applications that are descendants of the Window Manager (any program with a GUI (not sure about X-windows apps though)).
I personally encountered this problem when I was trying to get my website to display what is playing in iTunes currently. Supposedly OS X server has a program that enables this to work, but I have no access to that.
I did find an almost workaround for the problem by using the AppleScript syntax for talking to a remote machine, but using localhost as the address. This did not work good at all however, because for some reason my keychain authenticated the script to run only sometimes. The rest of the time it would pop up requests to authenticate in a dialog box. I never figured out why that happened.
The other route you may be able to take is the way I ended up doing it. I have a startup item that launches the applescript in the background and it saves the info from iTunes to a text file which apache can read. Unfortunately, this may not be a workable solution for you. If it is then you can use a program like DropScript or the custom app that I wrote which quickly launches my background script whenever I log in. I haven't used DropScript, so I can't say how quick it is, but the app I wrote only gets about half a bounce as it runs. So it is entirely unobtrusive even on my ancient machine (original 233mhz iMac).
If you need interaction with the applescript, than maybe you could do something with pipes to control the applescript? Be creative
Anyway, I hope this is helpful to you. I've had a long night, so this may be incoherent. I'll check again tomorrow.
|
|
We hope your rules and wisdom choke you / Now we are one in everlasting peace
-- Radiohead, Exit Music (for a film)
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
Mactoid,
Thanks for the response. I was interested to hear that you came up with a similar solution to me (although I've never heard your explanation for the problem before... a FEATURE????). I ended up making the applescript use an "on idle" handler instead of an "on run" handler, and had both the perl script and the apple script communicate by writing files, and checking for the existance of files written by the other.
This kind of works but is very cludgy.
BUT I've found a better solution.
On exactly the day I originally posted this problem, there was an AppleScript PERL module posted to CPAN ( www.cpan.org). The first version came out at exactly the time I was struggling with this problem.
I'm now in the process of integrating the AppleScript commands into the PERL script and running the whole thing from PERL.
It works well so far but has a long way to go. The main problem is that there's no good way to do error checking of the AppleScript from within the PERL script... all you can get is the applescript error number which can be quite useless sometimes.
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Sep 2000
Location: Springfield, MA
Status:
Offline
|
|
Originally posted by Brass:
...although I've never heard your explanation for the problem before... a FEATURE????
Well, I didn't say it was a good feature 
But it is by design, so we are just going to have to live with it.
That Perl module idea sounds interesting. I'm curious as to how that works out for you. Good luck with the rewrite, and let us know how it goes.
|
|
We hope your rules and wisdom choke you / Now we are one in everlasting peace
-- Radiohead, Exit Music (for a film)
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
Well the PERL module, Mac::AppleScript, works quite well for standard PERL scripts, but unfortunately suffers the same problems as the PERL system() call on Mac OS X (darwin).
It runs fine when run from the CLI, but when invoked from Apache (via a WWW request) the commands fail to work.
However, Mactoid, your explanation appears to be not quite correct.
You said, "The problem is that, as a security feature I believe, programs that aren't descendants of the Window Manager (apache, ssh, ftp.... eg the stuff that is still running after you log out) can't communicate with applications that are descendants of the Window Manager (any program with a GUI (not sure about X-windows apps though))."
I think you are close, but I'm actually testing these things from a remote machine (Solaris) SSH'ing into the Mac and running the PERL scripts via SSH. They work fine that way, even though the SSH, and tcsh processes are not descendants of the Window Manager. However they fail when run by Apache.
Any more ideas?
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Sep 2000
Location: Springfield, MA
Status:
Offline
|
|
Originally posted by Brass:
...I think you are close, but I'm actually testing these things from a remote machine (Solaris) SSH'ing into the Mac and running the PERL scripts via SSH. They work fine that way, even though the SSH, and tcsh processes are not descendants of the Window Manager. However they fail when run by Apache.
Any more ideas?
That is interesting. I'm not coming up with anymore ideas at the moment, however if it helps here is the source for all of my knowledge on the subject. 
Good luck, I'll let you know if I think of anything else.
|
|
We hope your rules and wisdom choke you / Now we are one in everlasting peace
-- Radiohead, Exit Music (for a film)
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|