 |
 |
calling applescript from php???
|
 |
|
 |
|
Grizzled Veteran
Join Date: Oct 2000
Location: Vancouver
Status:
Offline
|
|
Does anyone know if or how I can call an applescript (and pass it data) from a PHP file, and have the results returned back to the php file????
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status:
Offline
|
|
Server-side web scripting isn't exactly my field, but I'm pretty sure that the only way to do this would be to set up the web server for AppleScript "acgi" scripts (see the Mac OS X Server documentation) and invoke them from PHP just as you would from any other GCI.
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Oct 2000
Location: Vancouver
Status:
Offline
|
|
Hmm OSX Server says it supports ACGI files in apache, but it requires CLASSICK!!
From the OSX Server Admin Guide:
Apple also supports CGIs written in AppleScript, referred to as ACGIs. To run an ACGI, use the Mac OS X Script Editor to save the AppleScript as an Application with the Stay Open option. Then start Classic and the ACGI Enabler (in /Applications/Utilities) before you request the file from a browser.
Not realy an option for me for 2 reasons.
1) I am not going to run Classic on my webserver
2) My webserver is not running OSX Server. Just OSX.
I found anouther app called "acgi Dispatcher" but it wont launch, complains about a "shared libirary error"...
Any one have any other ideas??
|
|
|
| |
|
|
|
 |
|
 |
|
Moderator Emeritus 
Join Date: Mar 2001
Location: Austin, MN, USA
Status:
Offline
|
|
Try shell_exec() along with osascript.
$foo = shell_exec("osascript -e 'tell application \"Finder\" to beep'");
(That particular command may or may not work, as the Finder beeping doesn't seem to work unless you're sitting at the computer. I've never tried it through PHP)
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Oct 2000
Location: Vancouver
Status:
Offline
|
|
Originally posted by Xeo:
Try shell_exec() along with osascript.
$foo = shell_exec("osascript -e 'tell application \"Finder\" to beep'");
(That particular command may or may not work, as the Finder beeping doesn't seem to work unless you're sitting at the computer. I've never tried it through PHP)
Ya, I tryed that to.. as it turns out, osascript will not run when called my a non GUI user (like www). so the only way I was able to get this to work was to tell apache to run as me (on my iBook just for testing)
Im not sure if this is a bug in osascript, or if it is a security "feature" put in there by Apple, and there is no documentation on osascript (other than the man pages)...
Im going to put my project on hold till I can find an answer, as I dont think many people would want to have there web server running as a GUI user...
|
|
|
| |
|
|
|
 |
|
 |
|
Moderator Emeritus 
Join Date: Mar 2001
Location: Austin, MN, USA
Status:
Offline
|
|
Originally posted by Alex Duffield:
Ya, I tryed that to.. as it turns out, osascript will not run when called my a non GUI user (like www). so the only way I was able to get this to work was to tell apache to run as me (on my iBook just for testing)
I'm sure the problem isn't that you're trying to run it as a non-GUI user, but that you're trying to run it as a user other than what's logged in via the GUI. If you had another "GUI user" I don't think you could run Apache as that user and be logged in with yours and still get osascript to work.
I could be wrong, but I think it's similar to the problems I was having running scripts over SSH. It just doesn't want to work, even if the AppleScript doesn't have any good reason to use the GUI it seems like it has to.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Oct 2001
Location: London
Status:
Offline
|
|
|
(Last edited by Diggory Laycock; Dec 14, 2002 at 10:12 AM.
)
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Originally posted by Alex Duffield:
Ya, I tryed that to.. as it turns out, osascript will not run when called my a non GUI user (like www). so the only way I was able to get this to work was to tell apache to run as me (on my iBook just for testing)
Im not sure if this is a bug in osascript, or if it is a security "feature" put in there by Apple, and there is no documentation on osascript (other than the man pages)...
Side-effect of the security features in OS X and how AppleScript is implemented. osascript requires a connection to the windowserver, and for security reasons that can only be obtained if you are executing as either the currently logged in user (ie the one that owns /dev/console), or root. Since Apache is running as www (again, for security reasons), and www doesn't own /dev/console and is not root, the request to open a connection to the windowserver is denied.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Mar 2001
Location: Provo, UT
Status:
Offline
|
|
After reading several of these discussions over the past few weeks, I wonder if the solution isn't to do some communication between Apache and some server the runs the Applescript.
I don't know if you could make a "listener" script solely with Applescript. (I'm still learning it) However you certainly could with Python and have Python call Applescript. i.e. have python listen at some port and have the Python script run as a user.
That would give you a fair bit of security, it would seem.
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Nov 2000
Status:
Offline
|
|
Solving this problem would be something like 'xhost +www' with X. Looks like I'll be running Tomcat as root.
Here's another Applescript question.
Code:
tell application "Foo"
return {foo:val1, bar:val2, baz:val3}
end tell
Code:
/* Java, in case you couldn't tell :) */
NSAppleEventDescriptor result;
NSMutableDictionary errorInfo = new NSMutableDictionary();
result = contrivedExample.execute(errorInfo);
Assuming contrivedExample is of type NSAppleScript and has been initialized with the contents of the above script, how would one go about getting the key/value pairs out of result? I've got scripts that return strings working fine, but this record type is driving me mad. I'd rather not take the approach of returning a delimited string and parsing it that everyone else seems to be using. Returning "foo=val1|bar=val2|baz=val3" from the script would most likely work, but screams kludge to me.
Apple provides plenty of examples for making your apps scriptable, but seems to provide very little for controlling other apps w/o resorting to execing osascript.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
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
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|