If you have a mac, and don’t use Quicksilver, well, you should!
Here’s how to use Quicksilver to shorten URLs using bit.ly. This is useful for many things, but especially for posting links to twitter.
Obviously you need Quicksilver installed, and you also need to create an account with bit.ly, and get an API key. (API stands for application programming interface, which is basically a set of standard ways to interact with bit.ly using computer code.) You find the key listed under your account once you register. You’ll also need Growl, which is a program that delivers alerts from different apps to your mac.
So, to start, you open Applescript, and paste the following into a new script:
using terms from application "Quicksilver"
on process text longURL
-- Init
my growlRegister()
-- If we didn't get a text string then grab the URL from Safari
if longURL is "" then
tell application "Safari"
if document 1 exists then
copy the URL of the front document to longURL
end if
end tell
end if
-- Format the URL accordingly in case it was types sans http://
if (longURL does not start with "http://") then
set longURL to "http://" & longURL
end if
-- Convert the longURL
set shellScript to ("curl --url \"http://api.bit.ly/shorten?version=2.0.1&longUrl=" & longURL & "&login=YOUR_BITLY_ID" & "&apiKey=YOUR_BITLY_API_KEY " & "\" | grep shortUrl | grep -o http.*[/a-zA-Z0-9] ")
set shortURL to (do shell script shellScript)
-- Display success message
growlNotify("Short URL now in clipboard:", shortURL)
-- Open the shortURL in Safari to test it
--tell application "Safari"
--set URL of front document to shortURL
--end tell
set the clipboard to shortURL
end process text
end using terms from
using terms from application "GrowlHelperApp"
-- Register Growl
on growlRegister()
tell application "GrowlHelperApp"
register as application "Shorten URL" all notifications {"Alert"} default notifications {"Alert"} icon of application "Script Editor.app"
end tell
end growlRegister
-- Notify using Growl
on growlNotify(grrTitle, grrDescription)
tell application "GrowlHelperApp"
notify with name "Alert" title grrTitle description grrDescription application name "Shorten URL"
end tell
end growlNotify
end using terms from
Now, find in the script where I wrote in all caps YOUR_BITLY_ID and YOUR_BITLY_API_KEY — that’s where you plug in your info from bit.ly.
Next, save this file (I use the file name “Shorten URL”) in your Actions folder, which is located on your mac in:
Home -> Library -> Application Support -> Quicksilver -> Actions
One note — make sure your Actions folder appears in the Catalog in quicksilver. If it does not, open the catalog (apple-comma), go to Custom, and use the + sign on the bottom to find your Actions folder and add it in.
Rescan the catalog, and you’re done.
To use it, first copy a long URL to the clipboard. Then, invoke Quicksilver, paste the URL in, and tab to the second box. Type “Shorten URL” (or whatever you named the script), and hit enter.
You should see a growl alert with the new URL, and it will be in your clipboard. Paste away!
Credit where credit is due:
I didn’t write this script on my own, but found these two posts, which I used to create the script:
http://tanniespace.com/bitly-textexpander-applescript-win/
http://trumcgowan.tumblr.com/post/84901795/shorten-urls-using-quicksilver
Programming is all about remix, really… :-)

