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

Fantastic… You are really getting good at creating word clouds.
From: Shot Of Love


Thanks for doing these. While I’ve used word clouds before, I never thought of applying them to albums. These tell...
From: Slow Train Coming


I absolutely love these word clouds – the words, the colours, brilliant idea. I guess it helps if you...
From: The Freewheelin’ Bob Dylan


Dude, you should really have some prints/lithographs done and market them. I know my office would look cool *if it were only...
From: Self Portrait


I’m an old music lover but, new to writing music. I’ve written several ditties...
From: Songwriting Challenges – Where Do I Begin?


Gotta love this guy. Every damn word he says is true. One low cost way to start is to make...
From: Don’t Sign With A Label – Dick Dale


Just put 2 and 2 together and realized I’m currently in a class with Jarbas. How lucky am I?!
From: Birds On The Wires


I was pretty sure that the name “John Stump” was meant to be a joke, seeing...
From: A bit of humor for the musically inclined…


Hey Graham… where did you find the piece by John Stump? He’s my uncle, and...
From: A bit of humor for the musically inclined…


Word!
From: Don’t Sign With A Label – Dick Dale



members online

guests online

Join Today!

  • 7 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