Created
August 27, 2009 16:56
-
-
Save jaehess/176422 to your computer and use it in GitHub Desktop.
Quicksilver URL Shortener with bit.ly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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