Applescript can control Safari - But can Safari run Applescripts?

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

Why not make your script into an applescript:// URL, and then have the users run the resulting script?

Ooh, almost got excited there for a second, but that’s actually more hideous than having the server send the commands by Remote Apple Events… See, I don’t want the user to click a button, see the code behind the button, and then have to manually compile and execute the code. They’ll never, ever do it and I’d probably get yelled at for even programming something so clunky. That would actually be more complicated than teaching them to type out the posix path name of the path they need to input. If, on a normal web site, a user clicked a button and then the javascript code behind it popped up, in another program no less, and a user had to click a button to execute that javascript… let’s just say that programmer would be out of a job pretty quickly. Thanks for the idea though, I hadn’t even thought about applescript:// URL’s…

Maybe I could be a little more concise in my question - Is there any way (and I mean even a “what if I put on my obj-c hat and read through the WebKit api” kinda way), to have Safari execute Applescript embedded within a web page in the same manner in which it currently (like most browsers) executes Javascript embedded in a web page? I dream of this:

or even a

being possible. Imagine having a gallery of images open in the web interface, and with a click of a button in the web interface, being able to open all the selected (checked) images in photoshop on the client’s machine! It would make one fantastic productivity booster for us at least…

I should keep my mouth shut, but seeing’s how you appear to understand the security ramifications and are willing to take the risk… yes, it’s possible.

Use this forum’s internal search (not the Google search) to find ‘protocol helper’. Among the threads you’ll find something of use.

Peter B.


Now that’s what I call a solution… thank you!!!