OK, I’m losing my mind here a little. I’ve got a property cast as a string (it’s a URL as a string). If I leave it alone, I can then coerce it to a URL. If I transmogrify it through the text returned of a display dialog and coerced back to a string (since the dialog returns it as Unicode text), AppleScript tells me that it equals the original value, has the same class as the original value, but can’t be coerced to a URL. Here’s code that demonstrates what I’m talking about (requires an internet connection):
property the_url : "[url=http://www.macscripter.net]www.macscripter.net[/url]"
--just hit enter, so the_url = the_url_from_user
set the_url_from_user to text returned of (display dialog "What's the URL?" default answer the_url buttons {"Cancel", "OK"} default button 2 with icon 1) as string
my diplay_ip(the_url)
my diplay_ip(the_url_from_user) --errors on my machine: 'Can't make "http://www.macscripter.net" into a URL.', why?
return {the_url = the_url_from_user, class of the_url, class of the_url_from_user}
-->{true, string, string}
on diplay_ip(the_domain)
try
set the_url_record to (("http://" & the_domain) as URL)
(display dialog "The IP of " & the_url & " is: " & (dotted decimal form of host of the_url_record) buttons {"OK"} default button 1 with icon 1 giving up after 10)
on error the_error
(display dialog the_error buttons {"OK"} default button 1 with icon 0 giving up after 10)
end try
end diplay_ip
Oh, my machine: Mac OS 10.3.2 (soon to be 10.3.3), AS 1.9.3
It works in Jaguar. I don’ know why it would make a difference but does this work?
property the_url : "[url=http://www.macscripter.net]www.macscripter.net[/url]"
-- just hit enter, so the_url = the_url_from_user
set the_url_from_user to text returned of (display dialog "What's the URL?" default answer the_url buttons {"Cancel", "OK"} default button 2 with icon 1)
my diplay_ip(the_url)
my diplay_ip(my AsText(the_url_from_user)) -- errors on my machine: 'Can't make "http://www.macscripter.net" into a URL.', why?
return {the_url = the_url_from_user, class of the_url, class of the_url_from_user}
-- >{true, string, string}
on diplay_ip(the_domain)
try
set the_url_record to (("http://" & the_domain) as URL)
(display dialog "The IP of " & the_url & " is: " & (dotted decimal form of host of the_url_record) buttons {"OK"} default button 1 with icon 1 giving up after 10)
on error the_error
(display dialog the_error buttons {"OK"} default button 1 with icon 0 giving up after 10)
end try
end diplay_ip
on AsText(str) -- method 1
try
return (text of ((str as string) as record)) as string
on error -- plain text to begin with
return str
end try
end AsText
Upgraded to 10.3.3 and still getting the same results.
Thanks, Rob, that does work for me. The odd thing is, the final result is {true, string, Unicode text} where originally it was {true, string, string}. Hmm, that’s a head scratcher.
Same {true, string, string} here. And yes, some odd behaviours introduced in OS X and Unicode text, which works for some things and not for others, and apps which now only accept strings and not Unicode, and blah. Another eg (I’m sure there is a technical explaining for this, but it seems absurd):
items of "foo" --> {"f", "o", "o"}
items of ("foo" as Unicode text) --> ERROR