How does the [applescript] tag work?

How in heavens name does

(*this*)

work? From web page to applescript would be really useful.

Cheers

What do you mean by ‘How does it work?’. Take a look at the html source for the page, and at the status bar in your browser. It’s just using the ‘applescript’ url protocol, which allows you to pass a string formatted script to script editor, which is automatically opened as a script when clicked.

Just make a plain html link tag using…

<a href="applescript://com.apple.scripteditor?action=new&script=XXX">YYY</a>

… and replace XXX with your url-encoded script and YYY with the link text.

The forum back-end has a simple script or tool built into the html-generating code for automatically converting a script to a url-encoded string, which creates a valid url (not necessarily a valid script) from whatever code you paste into it.

Nice! I’m probably going to be using it on most of my (badly kept, identical) websites. Great fun!

OK, so I made an applescript to take the contents of a textedit window and format it to go into this applescript tag thing. But when i try to use the link, nothing happens. Applescript launches, but that’s it.


property baselist : "QWERTYUIOPASDFGHJKLZCVBMqertyuiopasdfghjklzxcvbnm"
tell application "TextEdit"
	set blab to the text of the front document
	set endtext to ""
	repeat with i from 1 to the number of characters in blab
		if character i of blab is in baselist then
			set endtext to endtext & character i of blab
		else
			set endtext to endtext & "%" & (ASCII number character i of blab)
		end if
	end repeat
	set the text of the front document to "<a href=\"applescript://com.apple.scripteditor?action=new&script=" & endtext & "\">" & the text returned of (display dialog "Link:" default answer "") & "</a>"
end tell

Any ideas?

The bbs version for converting a script to HTML bbcode form looked like this some time ago; not so sure now:

-- this script encodes the script text currently on the clipboard
try
	display dialog "Choose the link action and enter the link text:" buttons {"Append", "Insert", "New"} default answer "link text" default button 3
	copy the result as list to {link_text, script_action}
	set this_text to (get the clipboard) as string
	set this_text to my encode_text(this_text)
	if the script_action is "Append" then
		set the URL_opening to "[url=applescript://com.apple.scripteditor/?action=append&script="
	else if the script_action is "Insert" then
		set the URL_opening to "[url=applescript://com.apple.scripteditor/?action=insert&script="
	else if the script_action is "New" then
		set the URL_opening to "[url=applescript://com.apple.scripteditor/?action=new&script="
	end if
	set the clipboard to (URL_opening & this_text & "]" & link_text & "[/url]")
	display dialog "The encoded script has been placed on the clipboard." buttons {"OK"} default button 1 with icon 1 giving up after 2
on error error_message
	display dialog error_message buttons {"Cancel"} default button 1
end try

-- this sub-routine is used to encode text 
on encode_text(this_text)
	set the acceptable_characters to "abcdefghijklmnopqrstuvwxyz0123456789_"
	set the encoded_text to ""
	set the character_list to {}
	repeat with this_char in this_text
		set this_char to the contents of this_char
		if this_char is in the acceptable_characters then
			set the end of the character_list to this_char
		else
			set the end of the character_list to encode_char(this_char)
		end if
	end repeat
	return (the character_list) as string
end encode_text

-- this sub-routine is used to encode a character 
on encode_char(this_char)
	set the ASCII_num to (the ASCII number this_char)
	set the hex_list to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
	set x to item ((ASCII_num div 16) + 1) of the hex_list
	set y to item ((ASCII_num mod 16) + 1) of the hex_list
	return ("%" & x & y) as string
end encode_char

And for HTML form, Apple used to post this (but I can’t find it now)

-- this script encodes the script text currently on the clipboard
try
	display dialog "Choose the link action and enter the link text:" buttons {"Append", "Insert", "New"} default answer "link text" default button 3
	copy the result as list to {link_text, script_action}
	set this_text to (get the clipboard) as string
	set this_text to my encode_text(this_text)
	if the script_action is "Append" then
		set the URL_opening to "<a href=\"applescript://com.apple.scripteditor?action=append&script="
	else if the script_action is "Insert" then
		set the URL_opening to "<a href=\"applescript://com.apple.scripteditor?action=insert&script="
	else if the script_action is "New" then
		set the URL_opening to "<a href=\"applescript://com.apple.scripteditor?action=new&script="
	end if
	set the clipboard to (URL_opening & this_text & "\">" & link_text & "</a>")
	display dialog "The encoded script has been placed on the clipboard." buttons {"OK"} default button 1 with icon 1 giving up after 2
on error error_message
	display dialog error_message buttons {"Cancel"} default button 1
end try

-- this sub-routine is used to encode text 
on encode_text(this_text)
	set the acceptable_characters to "abcdefghijklmnopqrstuvwxyz0123456789_"
	set the encoded_text to ""
	set the character_list to {}
	repeat with this_char in this_text
		set this_char to the contents of this_char
		if this_char is in the acceptable_characters then
			set the end of the character_list to this_char
		else
			set the end of the character_list to encode_char(this_char)
		end if
	end repeat
	return (the character_list) as string
end encode_text

-- this sub-routine is used to encode a character 
on encode_char(this_char)
	set the ASCII_num to (the ASCII number this_char)
	set the hex_list to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
	set x to item ((ASCII_num div 16) + 1) of the hex_list
	set y to item ((ASCII_num mod 16) + 1) of the hex_list
	return ("%" & x & y) as string
end encode_char

See also:
http://web.archive.org/web/20070504191036/http://www.apple.com/applescript/scripteditor/12.html
http://www.jonn8.com/html/Convert_Script_to_MC.html