-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathURL-encode.applescript
40 lines (37 loc) · 1.47 KB
/
URL-encode.applescript
1
use AppleScript version "2.4" -- Yosemite (10.10) or lateruse scripting additionson handle_string(lbText) set _res to urlencode(lbText) -- to return the result to launchbar instead of copying it substitute -- the next line for the line after it (set the clipboard to _res) -- open location "x-launchbar:select?string=" & urlencode(_res) set the clipboard to _resend handle_stringon run set the clipboard to urlencode(the clipboard as text)end runon urlencode(theText) -- http://harvey.nu/applescript_url_encode_routine.html set theTextEnc to "" repeat with eachChar in characters of theText set useChar to eachChar set eachCharNum to ASCII number of eachChar if eachCharNum = 32 then set useChar to "+" else if (eachCharNum is not equal to 42) and (eachCharNum is not equal to 95) and (eachCharNum < 45 or eachCharNum > 46) and (eachCharNum < 48 or eachCharNum > 57) and (eachCharNum < 65 or eachCharNum > 90) and (eachCharNum < 97 or eachCharNum > 122) then set firstDig to round (eachCharNum / 16) rounding down set secondDig to eachCharNum mod 16 if firstDig > 9 then set aNum to firstDig + 55 set firstDig to ASCII character aNum end if if secondDig > 9 then set aNum to secondDig + 55 set secondDig to ASCII character aNum end if set numHex to ("%" & (firstDig as string) & (secondDig as string)) as string set useChar to numHex end if set theTextEnc to theTextEnc & useChar as string end repeat return theTextEncend urlencode