Created
January 12, 2010 19:49
-
-
Save rwc9u/275535 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| set the ClipURL to urlencode(the clipboard as string) | |
| set curlCMD to ¬ | |
| "curl --stderr /dev/null \"http://api.shortswitch.com/shorten?apiKey=YOUR_API_KEY&url=" & ClipURL & "\"" | |
| do shell script curlCMD | |
| set theResult to the result | |
| set theURL to grepURL(theResult) | |
| return theURL | |
| on grepURL(theText) | |
| set theResult to theText | |
| set AppleScript's text item delimiters to "<shortURL>" | |
| set theResult to second text item of theResult | |
| set AppleScript's text item delimiters to "</shortUrl>" | |
| set theLink to first text item of theResult | |
| return theLink | |
| end grepURL | |
| 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 = 32 then | |
| set useChar to "+" | |
| else if (eachCharNum ≠ 42) and (eachCharNum ≠ 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 theTextEnc | |
| end urlencode |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment