Just a few miscellaneous snippets on some of the above…
extracting plain text from encoded text
The conversion method I suggested initially used a hack devised by the ingenious Arthur Knapp (a.k.a. AdmiralNovia). Put simply, it extracts the plain text from any encoding through an implicit coercion to record.
In terms of explicit coercion, I suppose a near equivalent might be something like:
"http://www.apple.com/" as Unicode text
text of (result as text as record) as text as URL
--> {class:URL, scheme:http URL, path:"http://www.apple.com/", host:{class:Internet address, DNS form:"www.apple.com", port:80, dotted decimal form:"17.254.0.91"}}
However, if the source happens to be plain text, an explicit coercion will result in an error:
"http://www.apple.com/"
text of (result as text as record) as text as URL
--> error number -1700: "Can't make \"http://www.apple.com/\" into type record."
One of the cunning aspects of Arthur’s approach is that it exploits an ambiguity in the meaning of text - so it doesn’t error when fed plain text.
set-to vs. returning
The returning command is simply another way to assign a value to a variable - and is therefore synonymous with set-to. So instead of saying set x to y, we could say y returning x. The choice of syntax is largely down to preference (as it is when, say, starting a subroutine with on doSomething() or to doSomething()). To demonstrate, here’s a mixture:
set theStart to "http://www."
"apple.com" returning theMiddle
set theEnd to "/"
theStart & theMiddle & theEnd returning theURL
theURL
--> "http://www.apple.com/"
So, coming back to the question of the two-liner, the second line was needed because AppleScript normally expects the assigning of a variable to come at the end of a statement.
bug stomp
Consider it done: Bug ID# [u]4360112[/u]
To file a bug, you’ll need to be an Apple Developer Connection (ADC) member. (Membership is free.) Then, go to Bug Reporter, login and give details of the issue. Advice on sequence, format, etc. is available there, making the process of reporting a bit easier. Folks shouldn’t be too concerned about filing duplicate reports, since the more bugs Apple receives about an issue, the more likely it is to move up their priority list. It’s a great way to make sure we enjoy better products in the future!
reducing variable assignment
Where execution speed is critical, it’s possible to shave off a few milliseconds here and there by reducing the assignment of values to variables. Using a tell statement, for example, is one way to achieve this - although care should be taken to avoid confusion such as: tell 3 to beep. (An over-simplified example, perhaps - but you’ll get the idea if you try running it.) It’s also possible at times to get a bit carried away…
a better error message
I once tried a similar exercise for a different reason - and was also amazed to find sites with the unlikeliest names! But your point’s a good one, Adam. Perhaps the error message should read something like: “Invalid connection or URL.”
vanilla vs. shell
Pure native applescript with no external call to an application, a scripting addition or the shell (all of which carry an initial overhead). For this kind of job (where no heavy lifting is involved), good ol’ vanilla can be pretty hard to beat (IMO).
coercion confusion
It might be worth clarifying what I meant by that. It used to be possible to coerce Unicode text to a record directly:
"test" as Unicode text
result as record
--> {«class ktxt»:"test", «class ksty»:«data styl0001000000000010000E00030000000C000000000000»}
But that’s evidently no longer the case:
"test" as Unicode text
result as record
--> error: "Can't make \"test\" into type record."
However, by using an intermediate coercion to string (actually styled text), a record can still be produced:
"test" as Unicode text
result as string as record
--> {«class ktxt»:"test", «class ksty»:«data styl0001000000000010000E00030000000C000000000000»}
Um… my apologies for ‘going on’ a bit… :rolleyes: