Sal, will there be a upgrade version of AppleScript and the Script Editor for Jaguar?
Based on the release notes, this looks like the most significant AppleScript release since I started using Macs (when the release of System 7 was big news). I don’t have Panther, and it will likely be quite some time until I am able to afford it, but I can hardly wait based simply on the changes to AppleScript. I’m in pain!
Kudos to Sal and the entire AppleScript/AppleScript Studio team!
– Rob
Much of the work done with AppleScript this release is directly tied to the Panther code base and can’t be ported to earlier versions of the OS, even Jaguar.
However, in recognition that some scripters may work in environments requiring editing scripts in Mac OS X v10.2, a beta-version of the Script Editor application for Jaguar is posted at this hidden link:
http://www.apple.com/applescript/scripteditor/beta.html
It’s the same beta we released this year.[/url]
I look at URL Protocol Scripting as a great thing too. The potential is fantastic, and I wish it were in place and acting properly right now. The biggest complaint so far is that special characters aren’t recognized. (High Ascii), for instance the continuation character ¬ or any of the commonly used AppleScript key combos will bomb, or create a blank Script Editor window. Also, in forums such as this, it takes special care to get URL Protocol Messaging to work.
Click This
But if I add an ‘option + the ell key’ “¬” combo it dies, eg.,
display dialog "Hello! ¬
"
Not a practical example, but a simple one.
The above code for 'Click This" is…
applescript://com.apple.scripteditor/?action=new&script=display%20dialog%20%22Hello!%22
But if I were to follow Apples guidlines the code would look something like this…
applescript://com.apple.scripteditor?action=new&script=display dialog %22Hello!%22
In essence, the code posted above is altogether different from the suggested code format at Apple’s URL Protocol Messaging web site.
URL Protocol Messaging has great potential only If we could figure out a way of getting past the special character issue, then we’d be groovin’ for sure. But for now it seems as though we’ve hit a dead end, and a lot of folks just won’t give in to losing a lot of things in order to gain one thing.
If you download the formatting script from Apple “The Encoding Script”, here’s what you’ll get for the above code…
http%3A%2F%2Fwww%2Eapple%2Ecom%2Fapplescript%2Fscripteditor%2F12%2Ehtml
The above code may render in a specialized html page, but it will most certainly not work here.
OK, I’m confused and missing something obvious here. Why doesn’t this become a clickable link? Is it becasue the PHP routines are looking for http://?
Click Here
No encasing quotes around script code:
Click Here
No encasing quotes and a slash after scripteditor:
Click Here
Encasing quotes and slash after scripteditor:
Click Here
I think the problem is in the PHP routines generating URLs placed in messages.
Image Script
Encode space characters:
Image Script
EASY TO FIX:
Problem: forum encoder does not accept spaces in urls
Answer: Edit the encoding script from the Apple website to remove the space character from the list of acceptable characters. The space character was counted as acceptable to reduce the length of encoded URLs. It works encoded or not.
Problem: forum encoder needs forward slash after domain declaration
Answer: add forward slash after domain declaration as in:
applescript://com.apple.scripteditor/?action=new&script=
As for high ASCII problem. Sorry about that. It crept in late in the development process. It will be fixed. Until then, avoid using curley quotes and new line characters.
You can add this line to the encoding script to auto-generate a link style for this forum (be sure to also remove the space character from the string of acceptable characters):
set this_text to my encode_text(this_text)
set this_text to "[url=applescript://com.apple.scripteditor/?action=new&script=" & this_text & "]click for script[/url]"
set the clipboard to this_text
I’ll post a version of the encoding script on the URL Protocol page that generates the Macscripter style link.
My script, Convert Script to Markup Code can create AS URLs for entire scripts in Script Editor. It generates the straight HTML necessary for the URL but not the BBCode–a light modification can fix this. There is still the error Greg mentioned about high-Mac ASCII characters, however.
Jon
The only problems is not “high-ascii” characters, but every-browser-passing-those-characters-to-the-script-editor.
I worked some time ago in a little script called “Run ASCRIPT”, which did the same that the script editor is actually trying to do (with some more options): “run/copy/save to disk” applescript code.
There is not a definitive solution, unless you design the app to work only with text passed by a single browser (eg, Safari), except for a very complex work with javascript: (if browser is x then set carriage-returns to y, else if browser is x then set carriage-returns to y, else…).
The text passed from differents browsers does not use allways the same encoding. Also, it is not the same pass code from a regular link than pass code from a form (after clicking a button).
I think the only solution is url-encoding every character different than [:alnum:] chars, and pass such string to the script editor/whatever GURLGURL handler, which will decode the entire chain. As in:
property safeChars : "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_."
set theScript to "set x to "Sample string with special cháracterërs"
display dialog x"
set ASLink to "applescript://com.apple.scripteditor?action=new&script=" & my encodeText(theScript)
on encodeText(k)
set finalText to {}
repeat with i in k
if i is not in contents of safeChars then set i to "%" & my encodeChar(i)
set finalText's end to i as Unicode text
end repeat
return "" & finalText
end encodeText
on encodeChar(this_char)
try
((last character of ({{coercionTrick:this_char as Unicode text}} as string)) as C string) * 5
on error msg
return text from character 22 of msg to character 23 of msg
end try
end encodeChar
Nicely done! Thank you for contributing this to the community.
URL Protocol Support in the Panther Scripte Editor is designed to work with Safari. Other browsers or apps may or may not have a problem with the extended URLs.
Here’s a version of the encoding script that creates a link for use here at macscripter.net:
encoding script
I’ve updated my Convert Script to Markup Code scripts to handle the modifications to the AS URL for posting as BBCode on this BBS. I’ve also added two new scripts for converting Project Builder or Xcode AppleScript as well. The scripts can be directly downloaded from [url=http://homepage.mac.com/jonn8/as/dist/Convert_Script_to_MC.hqx]http://homepage.mac.com/jonn8/as/dist/Convert_Script_to_MC.hqx[/url] and will be on ScriptBuilder’s shortly. (The Script Debugger version, sadly, is still included but has not been updated as I wrote it using the demo version of the app and my demo has expired. If someone would like to update it, by all means, go ahead.)
Thanks for the compliment, Sal. You know, a few months ago I left you a private message on this board announcing these scripts and offering to have Apple post them (the offer still stands). It looks like you’ve got a new user name so perhaps you didn’t check that account.
Jon
Thanks for all the great tips and scripts Sal and Jon. Jon it looks like your script leaves the ampersands around the filename variable in the text…
Open the AppleScript &str-hex.scpt& in a new Script Editor window.
[This script was automatically tagged for color coded syntax by Script to Markup Code]
Good catch, Greg. I’ve got a fix on the way. If you can take down the previous upload to ScriptBuilders, a new version will be posted within the hour.
Jon
Will do. I deleted v2.1.6, so you can use the same name for the next upload as the 2.1.6 version no longer exists in the db.
I forgot my old username… what was it?
I’ll put a link to the scirpts on the website.
BTW< I updated the Protocol webpage to include a version of the encoding script for working with macscripter:
http://www.apple.com/applescript/scripteditor/12.html
I can’t get the MacNN forums to accept it though. Their PHP parser adds HTML breaks in the middle of the code.
It was “sal” with your apple email address.
Your username was, oddly enough, “sal”. The message (sent on 7/26) is still listed in my outbox waiting to be read.
Jon
Only for the records of somebody interested, this is false. I was yesterday too tired, sorry. I’ll rewrite this paragraph:
I think the only solution multibrowser is encoding every character using, eg, a hexadecimal notation, so a “0A” is allways a “0A” when it arrives to the GURLGURL handler. This is the solution I suggested some time ago for Peter Bunn’s Missing Link, where it must be passed a file path to an applescript from random browsers.
However, the original solution is not still good enogh, since it only parses the mac-ascii table, eg:
So, we still need some extra help (eg, UTF-8):
Cheers :oops:
Sal,
I just noticed that the link to MacScripter.net is broken. Here’s what it points to:
http://www.apple.com/applescript/scripteditor/macscripter.net
– Rob