• grahamenglish.net – Blog
  • grahamenglish.com – Artist Site

Graham English Blog Archives

Musician, Author, and Entrepreneur

  • Blog
  • Consulting

How To Shorten URLs With Bit.ly Using Quicksilver

July 8, 2008 By Graham English

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}'")
Share on Pinterest
There are no images.

Filed Under: Prose, Technology Tagged With: API, Apple, AppleScript, Bit.ly, code, Firefox, hacks, LifeHacks, Mac, Metamark, programming, Python, Quicksilver, Safari, scripting, Technology, URL

About Graham English

Graham English is a musician, author, and entrepreneur.

Comments

  1. JohnB says

    July 11, 2008 at 1:22 PM

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

  2. Graham English says

    July 11, 2008 at 4:41 PM

    Excellent! Glad I could help. 🙂

Graham English
  • Facebook
  • Instagram
  • LinkedIn
  • Twitter
  • YouTube
image title

Crank your sound up to X with Apple's premier recording software and Logic Pro X For Dummies

Read the blog
Listen to music

Archives

  • September 2014
  • July 2014
  • March 2014
  • June 2013
  • February 2013
  • January 2013
  • April 2012
  • November 2011
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007
  • February 2007
  • January 2007
  • December 2006
  • November 2006
  • October 2006
  • September 2006
  • August 2006
  • July 2006
  • June 2006
  • May 2006
  • April 2006
  • March 2006
  • February 2006
  • January 2006
  • December 2005

Follow me on Twitter

My Tweets

Follow me on Facebook

Follow me on Facebook

Recent Posts

  • Final Score
  • iGrahamEnglish is just GrahamEnglish
  • Cleaning Up My Act
  • Logic Pro Mixing, Metering, And Loudness Explained
  • Attention Musicians: Comfortably Avoid Hearing Loss With Custom Fitted Earplugs

Graham is a singer/songwriter and jazz-trained keyboard player, music producer and studio musician, best-selling author of Logic Pro X For Dummies, and serial entrepreneur.

  • Facebook
  • Instagram
  • LinkedIn
  • Twitter
  • YouTube


  • About
  • Contact
  • Wiki
  • Legal Policy
  • Privacy Policy
  • Living Room Rules

Copyright © 2023 Graham English