I’m developing a web-based image management system in Rails that is primarily for remote users to log in, manipulate images, and put keywords on them. Of course, someone needs to make the images available to the users in the first place, and so there’s a administration panel that’s available only to people on the local subnet (so, only to users who connect via the intranet / from within the server’s own subnet / however you want to phrase it). What I want to be able to do is have the administration panel be able to hook in to this massive pile of applescripts I have laying around for various tasks, so that these tasks can be completed on the client instead of the server. Also, it would allow us to use some of the Applescript’s dialog boxes to give the administration panel a more natural, Mac-like user interface with all the bells and whistles of system-standard dialog boxes. For example:
When an admin defines a new job for the system, they have to enter a pathname. I’d like to implement a button on the web page itself similar to the Browse… button in a file upload form that, when clicked, executes something like:
tell application "Safari"
set myPath to "/Volumes" & POSIX path of (choose folder with prompt "Where are the images for this job located?")
do JavaScript "document.getElementById('textbox').value = " & myPath in front document
end tell
I hope someone else can see the usefulness of this on an intranet. I know that allowing applescripts to execute from a web page would constitute a huge security hole, but in this case I really have the most benign intentions at heart, and no one will even have access to this section of the site unless they were willing to run the applescripts in the first place. Without something like this, my poor administrators will have to sit there and type out these huge paths (or copy and paste them, still a hassle) every time they want to add a job to the system. With something like this, this interface will work essentially the same as our current Applescript/Cocoa interface while allowing me to make use of all my nice, streamlined Rail’s class methods for the processing work.
I’ve googled around and I can’t seem to find anything on the subject of running applescripts from a web page (I thought there might be some function like ‘window.runApplescript(code)’ in Safari’s JavaScript implementation, but if there is it’s not advertised). Could there be some secret way to do this, perhaps that someone has to enable it in a plist somewhere? If not, could Safari be extended to do this in some way? I could always have the page send an XMLRequest to the server that triggers the server (also a mac) to send a remote applescript event back to the client computer to achieve the same purpose, but that’s not very clean and involves a lot of extra back and forth and I bet any solution along those lines would be horribly error-prone.
(may be important: This would be primarily on 10.3/Safari 1.3.2 but increasingly also on 10.4/Safari 2.something)
Thanks for any info anyone has…
–
Steve