python script (for Mac)

For a while I have been using a simple AppleScript script to convert URLs into shortened URLs. The flow goes something like:

  • Initiate script from Quicksilver
  • Grab URL from the front-most window in Safari
  • Submit URL to URL shortening service (previously, but more recently
  • Copy shortened URL to system clipboard (for pasting into Twitterific)
  • Notify of process completion via Growl

I’ve tried a number of different workflows including bookmarklets and the like, but this one works best for me (read: I honestly don’t care what you think of this flow or what you do instead… this is what I prefer).

Recently I discovered a new URL shortening service,, and decided to give them a try. However, unlike most services, doesn’t simply return the shortened URL. Instead it returns either an XML or JSON structure that includes the shortened URL along with some other data. Quickly realizing that AppleScript doesn’t handle JSON very well, I decided that this would be a good opportunity to start learning Python. The result was the following Python script:

It follows the same flow as mentioned above, making use of a couple of Python modules (which are required for running this script): simplejson and appscript. Put this script in a directory that Quicksilver scans (I think the Terminal Quicksilver plugin is also required). If you want to authenticate to, add your username and password to your ~/.netrc file. I also set the script’s file icon to be the icon, so it will be displayed in the Growl notification.

Have you written a response to this? Let me know the URL: