latest waveforms



How To Shorten URLs With Bit.ly Using Quicksilver

Quicksilver BitlyA URL shortener service called Bit.ly launched today. It has some great features that convinced me to switch from using Metamark to shorten my URLs. Since I have a slick script that allows me to use the Metamark API from Quicksilver, I had to modify the code to make it work with Bit.ly.

Copy the following script, name it what you want, and save it in your home folder. When you want to shorten a URL in Safari, run the script from Quicksilver and it will put the shortened URL on your clipboard, ready for pasting.

#!/usr/bin/env python

usage = '''
Takes the URL of the frontmost Safari window/tab and
shortens using the service at bit.ly. The shortened
URL is put on the clipboard, ready for pasting.
'''

from urllib import urlopen, urlencode
from os import popen

# Get the URL of the frontmost Safari window/tab though AppleScript.
applescript = '''tell application "Safari"
URL of front document
end tell'''

url = popen("osascript -e '" + applescript + "'").read().strip()

# Get the shortened URL from bit.ly.
shortURL = urlopen('http://bit.ly/api?url=' + url).read()

# Put the shortened URL on the clipboard.
popen('pbcopy', 'w').write(shortURL)

If Firefox is your thing, modify the AppleScript tell to:

applescript = '''tell application "Firefox"
set myFirefox to properties of front window as list
get item 3 of myFirefox
end tell'''

Update: I also use the following script as a Quicksilver trigger to expand shortened URLs and protect myself from surreptitious rickrolling. Just copy the shortened URL you want to expand (TinyURL, Bit.ly, etc.) and trigger the script.

tell application "Quicksilver" to show large type (do shell script "curl -Is `pbpaste` | grep Location | awk '{print $2}'")


Rating: 1 Star2 Stars3 Stars4 Stars5 Stars
Loading ... Loading ...


Comments


  1. JohnBNo Gravatar says:

    THks G — using it and added it to the betaworks site

  2. Excellent! Glad I could help. :)

  3. [...] bit.ly, python, and quicksilver (plus growl) 26 04 2009 A fellow, Graham, made a nice little python script to shorten urls with bit.ly here. [...]

Leave a Comment



Living Room Rules: Please respect this space as you would respect the home of a friend who invites you over for coffee.



recent comments

wow thats strange there has to be some way to figure that out hmm nope cant find it it probally has to do with...
From: Real-Life Optical Illusions


You’re welcome.
From: iQuickTwitter – My Quicksilver + Twitter + iChat + Growl Hack


Thanks. I’ve been messing w/ this all day. Your instructions were...
From: iQuickTwitter – My Quicksilver + Twitter + iChat + Growl Hack


Gorgeous. I recommend the Workshop to anyone who wishes to learn how powerful...
From: Gustav Holst, The Planets Op. 32 I. MARS, the Bringer of War


Incredible!
From: Ralph van Raat Plays Rzewski’s Winnsboro Cotton Mill Blues


Here you go: Word Cloud
From: Shot Of Love


What the hell is a word cloud kemosabi, and I RTFR’s
From: Shot Of Love


Thanks!
From: Shot Of Love


You’re certainly welcome. And it’s been my pleasure!
From: Slow Train Coming


Thanks! Glad you’re getting something out of them. I know I am!
From: The Freewheelin’ Bob Dylan



members online

guests online

Join Today!

  • 8 Guests

Subscribe

Get my music, audio/video, and articles delivered to you by RSS, iTunes, or email:


Your privacy is guaranteed.

More subscribe options...

about graham

I'm a songwriter and recording artist who sings, plays keyboards, and explores the vast world of sound hoping to find some magical moments along the way. I'm also a Mac geek.

TwitterCounter for @grahamenglish




facebook connect

Connect with Facebook



google friend connect



tags