Hi, I know a bit about AppleScript already, but I’m a bit confused with all these “text item delimiters” and whatnot.
I’m trying to ‘coralize’ a web address so it accesses a cache from the CoralCDN, a commonly used cache for site that have been ‘dugg’ or ‘/.ed’ or whatever.
What I can’t do is stick the “.nyud.net:8080” in between the ‘.com’ and ‘/’. I need it to also regonize some other .whatevers, like .net, .us, .tk, and it’s giving me a headache.
This handler that I made to workout domain names, find in code exchange here. Just add a bit to the suffix, not to hard. Post a full URL before and after and I can do it for you, if you get stuck.
set theUrl to "http://www.apple.com/support/tiger/internet/"
set text item delimiters to {"/"}
try
tell theUrl to set coralURL to text items 1 thru 2 & (text item 3 & ".nyud.net:8080") & text items 4 through -1 as Unicode text
on error
tell theUrl to set coralURL to text items 1 thru 2 & (text item 3 & ".nyud.net:8080") as Unicode text
end try
set text item delimiters to {""}
Small nitpick James; I would preserve the class of the input. (Besides me just thinking that it’s proper, it should be noted that StandardAdditions’ URL class currently does not support Unicode text.)
on coralizeURL(someURL)
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to "/"
try
tell someURL to set someURL to "" & text items 1 thru 2 & ("/" & text item 3 & ".nyud.net:8080/") & text items 4 thru -1
on error
tell someURL to set someURL to "" & text items 1 thru 2 & ("/" & text item 3 & ".nyud.net:8080/")
end try
set AppleScript's text item delimiters to ASTID
return someURL
end coralizeURL
coralizeURL("http://www.apple.com/support/tiger/internet/")
--> "http://www.apple.com.nyud.net:8080/support/tiger/internet/"