Shortening URLs via bit.ly from the CLI

I was experimenting tonight with some ways to add more automation to my workflow. One process that is (relatively) time-consuming is the process of generating short URLs via bit.ly. This site had a brief tutorial on how to use curl to do it, but the shortened link didn’t show up in my link history. Upon browsing the bit.ly API documentation, though, I was able to fairly quickly piece together a command line that will shorten a URL via bit.ly and put the shortened URL in the user’s link history.

Note that in order to use this command, you’ll need your bit.ly API key. Your API key is easily accessed from your account settings page.

Here’s the command I tested (works on Mac OS X 10.6.4):

curl 'http://api.bit.ly/v3/shorten?login=<bit.ly login>&apiKey=<bit.ly API key>&longURL=<Long URL to be shortened>&format=txt'

In order to make this truly usable, there are some additional things that have to happen. The long URL has to be properly encoded, as it can’t have any spaces or special characters, for example. But otherwise, this command is a workable solution to shortening a URL from the command line. All I need now is a small AppleScript around this and then I’ll have a URL shortening script I can bind to a hotkey. That should help speed the process up!

Tags: , ,

2 comments

  1. Jason Boche’s avatar

    What’s your use case? Chapter writing? I used URL shortening a lot in creation of the vCalendar entries, however, I’ve not seen bit.ly or the like used in documentation or books elsewhere.

  2. slowe’s avatar

    Jason,

    Good question! I’m really striving to make it easier and faster to move information through my systems. I go through a LOT of URLs, as I’m sure you and most others in our industry do. Automating the process of shortening URLs makes it easier and faster for me to share those URLs with others via my blog or Twitter. If I can save five minutes a day, then I’ve saved over 20 hours a year—that’s pretty significant.

Comments are now closed.