set the ClipURL to (the clipboard as string)
ignoring caseif ((characters 1 through 4 of ClipURL as string) is not"http") thenreturn"Malformed URL."else
set the EncodedClipURL to urlencode(ClipURL) of me
set curlCMD to ¬
"curl --stderr /dev/null \"http://bit.ly/api?url="&EncodedClipURL&"\""--Run the script and get the result:
set tinyURL to (do shell script curlCMD)
return tinyURL
endifend ignoring
on urlencode(theText)
set theTextEnc to ""
repeat with eachChar in characters of theText
set useChar to eachChar
set eachCharNum to ASCII number of eachChar
if eachCharNum =32then
set useChar to "+"else if (eachCharNum ≠ 42) and (eachCharNum ≠ 95) and (eachCharNum <45or eachCharNum >46) and (eachCharNum <48or eachCharNum >57) and (eachCharNum <65or eachCharNum >90) and (eachCharNum <97or eachCharNum >122) then
set firstDig to round (eachCharNum /16) rounding down
set secondDig to eachCharNum mod 16if firstDig >9then
set aNum to firstDig +55
set firstDig to ASCII character aNum
endifif secondDig >9then
set aNum to secondDig +55
set secondDig to ASCII character aNum
endif
set numHex to ("%"& (firstDig as string) & (secondDig as string)) as string
set useChar to numHex
endif
set theTextEnc to theTextEnc & useChar as string
end repeat
return theTextEnc
end urlencode