I hope someone can help me with this. I am working on a web application in which we have static Excel report templates and we populate them with dynamic data when a user clicks on a link in the web browser. Currently the application only works with IE on the PC and VBScript but we need to make the application compatible with Safari and Mac.
Here are the steps that need to happen when a use clicks on a report:
download Excel template
launch excel and open template
download dynamic data
populate template with data
I think I understand generally how I could accomplish each task using AppleScript. I’m not at all sure how to have the steps happen upon clicking a link in a browser. Should the link download an AppleScript script? I’m sure this would not launch automatically so the user would have to find it in the finder and double click to open it. If so, how could I possibly parameterize the script per request? It seems like plain text script files are not double-clickable.
Is there no way to invoke or control AppleScript from javascript within Safari?
I’m starting to think this control flow might not be at all possible. Any suggestions?
You came to the right place. Here around there are several folks which can answer your question (me, for example :lol: ).
Create an applescript application containing the following SAMPLE CODE:
Create in your mind a new protocol name for your app (as “http” or “mailto”). For example: “bakunin”.
Go to your app and modify the “plst” resource (use a resource-fork editor). Or, if you save the app using the new “bundle” format, modify the “Info.plist” file. Add the following:
Logout/login or compress-the-app, delete-the-app, uncompress-the-app. The goal is that LaunchServices reads the “plist” info and recognizes and registers your app to handle the new “bakunin” protocol. When your users download-uncompress your app, LaunchServices will do the job automatically.
Write a SAMPLE HTML page:
Open it in a brower (eg, Safari) and click the link.
Basically, you create a protocol-helper application (as Outlook Express, KDX or Hotline), then you can pass any parameter to such app from a link, such as “bakunin:zp.cgi”, which instructs to your app to create a new excel document, and populate it with data downloadable from “zp.cgi” (for example).
(And no, there is not VBScript nor ActiveX nor something similar built-in in Mac OS X)
I can only manage to invoke my AppleScript application with the URL protocol when it is already open. I can’t figure out how to get it to launch when I open the URL. I changed the Info.plist as described, put the app in ~/Applications/ and restarted the machine.
It works as expected when the app is already open. But when the app is closed Safari gives a message:
Is the “rapt” protocol defined in the LaunchServices prefs?
Eg:
do shell script "defaults read 'com.apple.launchservices' | grep -e 'U:rapt'"
If it returns something, it maybe defined.
It if is defined, maybe it is malformed? Then pick MisFox: http://www.clauss-net.de/misfox/misfox.html
Quit your app. Delete the old “rapt” entry and add it again.
Some times, if the problem persists, you need additionally define a original “creator type” for your app. By default, an applescript applet is “aplt”. Change it to “xxxx”, then re-define your “rapt” entry using MisFox. You may need define the new creator type in several places:
-If carbon app, you should:
· Modify the “BNDL” resource using a resource editor (eg, Resorcerer)
· Modify the “plst” resource --“CFBundleSignature”
· Modify the creator type itself. Eg, run the following:
tell app "Finder" to set creator type of yourApp to "xxxx"
-If cocoa app (package), you should:
· Modify the “Info.plist” file (/Contents/Info.plist)
· Modify the PkgInfo file (/Contents/PkgInfo)
You may also need to save your protocol script app as “Stay Open”. In similar uses, I’ve found this necessary to get it to fire properly. Don’t know why. You can add a line at the end of the script “Tell me to quit”, if you don’t want the app in the Dock all the time… but it’s faster to respond in use if you don’t quit it.