Skip to content

Instantly share code, notes, and snippets.

@jaehess
Created August 27, 2009 16:56
Show Gist options
  • Select an option

  • Save jaehess/176422 to your computer and use it in GitHub Desktop.

Select an option

Save jaehess/176422 to your computer and use it in GitHub Desktop.
Quicksilver URL Shortener with bit.ly
#!/usr/bin/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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment