A 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}'")
JohnB says
THks G — using it and added it to the betaworks site
Graham English says
Excellent! Glad I could help. 🙂