Cl.ly TextExpander URL shortener
I have been testing out TextExpander and for the most part have been really impressed by its time saving goodness. I like the inbuilt bit.ly snippet which enables you to shorten any URL copied to your clipboard and insert the shortened URL into any text area on your mac. However I have been using the cl.ly service from @getcloudapp which produces URLs only 16 17 characters long (nice for saving space in tweets) and so I decided to code my own cl.ly URL shortener in Applescript for use in TextExpander. Here is the result.
set Username to "user@email.com"
set Pword to "passwordhere"
set the ClipURL to (the clipboard as string)
ignoring case
if ((characters 1 through 4 of ClipURL as string) is not "http") then
return "Malformed URL."
else
set curlCMD to "curl --digest -u '" & Username & ":" & Pword & "' -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{ \"item\": { \"name\": \"" & ClipURL & "\", \"redirect_url\": \"" & ClipURL & "\" } }' http://my.cl.ly/items"
-- Run the script and get the result:
set clURL to (do shell script curlCMD)
set oset to offset of "http://cl.ly/" in clURL
set clURL to text (oset) thru (oset + 16) of clURL
return clURL
end if
end ignoring
Implementation
To implement this function create a new text expander snippet and change its content type to AppleScript (this is so it doesn't paste the code when you trigger the abbreviation but executes it). Then paste in the above code filling the email and password variables with your account details (not got one? Get one here).
This is by no means a perfect solution. For a start you have to enter your credentials in plaintext into the script for it to run (a security concern and not great for distribution). Secondly due to AppleScirpt’s complete lack of text phrasing functionality if @getcloudapp changes the length of their URL which they are likely to do as there are only 226,920 permutations of 3 character case-sensitive alpha-numeric strings, the script will fail with very little grace.
Update: They filled the URL space (all 226,920 permutations) and now the URLs are 17 characters long. The script has been updated accordingly. They may fill the URL space happen again however there are now 13,388,280 permutations of 4 character case sensitive alphanumeric strings available so we are safe for now.
Anyway, please let me know what you think via commenting bellow as I am looking at ways of improving this and suggestions are most welcome.

Did a double take at "Clegg: family finances in a ‘state of emergency" and then noticed the colon.