Open this Scriplet in your Editor

Hello, How does one implement the “Open this Scriplet in your Editor:” link on this (and other) sites in order to open applescript code in the script editor? The applescript itself is encoded - in hex? - after the link that is called in the html. I’d like to be able to use the link on a site. I searched and couldn’t find an answer; is it a trade secret? :slight_smile: Thanks.

It’s not secret, and the scripts are just recoded as HTML (one long string - returns aren’t used in HTML) so they’ll appear as they should in the forum. In earlier versions of OS X, there was an article in Apple’s developer docs with an AppleScript for doing the encoding and a description of the AppleScript bbcode link and how to declare it on your server. I can’t find it now because I can’t recall what it was called.

With respect to the bbs, nothing secret is done; there’s a proprietary php script that encodes the submitted script and appends it to the link, and there’s code so the server recognizes the [AppleScript]…[/AppleScript] tags.

Thanks - I didn’t think it was very secret (!) as the same kind of links are on other sites. I found some info on encoding and someone else’s attempt to do what I’m thinking, so I think I’ll try and write an applescript that takes the text of a script from the clipboard and encodes it and formats it into an “Open in Script Editor” link for pasteing…

URL Protocol Messaging

Basically:

applescript://com.apple.scripteditor?action=new&script=

.followed by the encoded script.

Thanks for that link! - songdog

Thanks, Bruce – senior moments are accelerating in frequency! :o

Forgot to post the encoding scriplet, after all; code borrowed from http://forums.macosxhints.com/showthread.php?t=78804

Copy the text of your Applescript to your clipboard (right out of the Script Editor), run the script below, and then paste your encoded Applescript into a Web document:


set TheCode to do shell script "python -c 'import sys, urllib; print urllib.quote(sys.argv[1])' " & quoted form of (the clipboard)
set the clipboard to "Click here to open this script <a href=\"applescript://com.apple.scripteditor?action=new&script=" & TheCode & " \" target=\"_blank\">in your Script Editor </a>:"

Below is the Applescript above, encoded thusly for the Web:


Click here to open this script <a href="applescript://com.apple.scripteditor?action=new&script=set%20TheCode%20to%20do%20shell%20script%20%22python%20-c%20%27import%20sys%2C%20urllib%3B%20print%20urllib.quote%28sys.argv%5B1%5D%29%27%20%22%20%26%20quoted%20form%20of%20%28the%20clipboard%29%0Dset%20the%20clipboard%20to%20%22Click%20here%20to%20open%20this%20script%20%3Ca%20href%3D%5C%22applescript%3A//com.apple.scripteditor%3Faction%3Dnew%26script%3D%22%20%26%20TheCode%20%26%20%22%20%5C%22%20target%3D%5C%22_blank%5C%22%3Ein%20your%20Script%20Editor%20%3C/a%3E%3A%22 " target="_blank">in your Script Editor </a>: