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}'")

If you want to be notified the next time I post something, sign up for email alerts or subscribe to my RSS feed. Thanks for visiting!



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

Eye opening, and elegant. Her comparison between...
From: Evelyn Glennie: How To Listen To Music With Your Whole Body


Graham, I have attended another Paul Oertel...
From: Evelyn Glennie: How To Listen To Music With Your Whole Body


So true.
From: Evelyn Glennie: How To Listen To Music With Your Whole Body


Wow. Awesome. Strange how it is so easy to NOT pay...
From: Evelyn Glennie: How To Listen To Music With Your Whole Body


You could always figure out what your favorite songs are,...
From: Songwriting Challenges – Where Do I Begin?


how do you keep from mentally regurgitating intervals from...
From: Songwriting Challenges – Where Do I Begin?


Cheers, Peter. That tune doesn’t really deserve any money to be pumped...
From: Graham English Talks Episode 15


I don’t have an answer. The trite answer is...
From: Why Singing What You Hear Is Important To Your Ear Training


about how many times would u say one would have to...
From: Why Singing What You Hear Is Important To Your Ear Training


hi graham its peter….LogicLover… inspiring stuff mate seriously...
From: Graham English Talks Episode 15



members online

guests online

Join Today!

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




google friend connect



tags