Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > calling applescript from php???

calling applescript from php???
Thread Tools
Grizzled Veteran
Join Date: Oct 2000
Location: Vancouver
Status: Offline
Reply With Quote
Nov 21, 2002, 06:12 PM
 
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????
Alex Duffield
http://www.incontrolsolutions.com
Fatal error: Call to undefined function: signature() in /usr/local/www/htdocs/showthread.php on line 813
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Nov 21, 2002, 07:31 PM
 
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.
Rick Roe
icons.cx | weblog
     
Grizzled Veteran
Join Date: Oct 2000
Location: Vancouver
Status: Offline
Reply With Quote
Nov 22, 2002, 04:27 PM
 
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??
Alex Duffield
http://www.incontrolsolutions.com
Fatal error: Call to undefined function: signature() in /usr/local/www/htdocs/showthread.php on line 813
     
Xeo
Moderator Emeritus
Join Date: Mar 2001
Location: Austin, MN, USA
Status: Offline
Reply With Quote
Nov 25, 2002, 10:32 PM
 
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
Reply With Quote
Nov 27, 2002, 04:27 PM
 
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...
Alex Duffield
http://www.incontrolsolutions.com
Fatal error: Call to undefined function: signature() in /usr/local/www/htdocs/showthread.php on line 813
     
Xeo
Moderator Emeritus
Join Date: Mar 2001
Location: Austin, MN, USA
Status: Offline
Reply With Quote
Dec 2, 2002, 07:42 AM
 
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
Reply With Quote
Dec 14, 2002, 08:26 AM
 
How about this:

http://www.sentman.com/acgi/

Alas it costs $35 - but it may do what you want.

[edit]

or it looks like you can set up another instance of apache running as you.

http://www.macdevcenter.com/pub/a/ma...rl.html?page=2
(Last edited by Diggory Laycock; Dec 14, 2002 at 10:12 AM. )
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Dec 14, 2002, 04:18 PM
 
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
Reply With Quote
Dec 14, 2002, 08:16 PM
 
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
Reply With Quote
Dec 15, 2002, 08:46 AM
 
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.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:23 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2