Since I’ve switched from NetNewsWire to Reeder one of the first scripts I need to convert is my Bitly url shortener. I post a lot of links to App.Net1 Many ADN clients handle links quite well, using the features of the API to auto shorten them for you or even put link text in place. Unfortunately neither of the main Mac clients handle links well yet. So an url shortener is a must. A final advantage of using Bitly is you can go back and look over all the links you’ve posted. Nice when you remember discussing an article but can’t recall the article off the top of your head.
To get an url shortener to work with Reeder you first have to setup its services. Reeder can actually do a remarkable amount of sharing to various services via menubar icons or keyboard shortcuts. However you have to set them up yourself. Go to Preferences and then to the Services tab. Then click on the Copy Link item. Make sure it’s enabled and that you set ^C as the keyboard shortcut. (You can actually set it to whatever you want — in the script below I assume it’s set to ^C)
sudo pip install -e git://github.com/bitly/bitly-api-python.git#egg=bitly_api
Even though it’s no longer supported I’m using appscript to do the Apple Events. Feel free to convert this to calling Applescript if you wish. I was just in a hurry and borrowed the code from my original script. If you don’t have appscript installed, install it from the command line.
sudo pip install appscript
The script is fairly self-explanatory. I use GUI scripting to control Reeder since unlike NetNewsWire it doesn’t support Applescript.
#!/usr/bin/python # -*- coding: utf-8 -*- ### URL Shortner for Reeder ### You must first set up the Copy Link service and assign it a ^C shortcut. from appscript import * import sys import time import bitly_api from osax import OSAX bitlyUserName = 'user' bitlyAPIKey = 'apikey' def shorten(url): bitly = bitly_api.Connection(bitlyUserName, bitlyAPIKey) short = bitly.shorten(url) return short['url'] def shortenReeder(): Reeder = app(u'/Applications/Reeder.app') Reeder.activate() SE = app(u'System Events') SE.keystroke('c', using=k.control_down) sa = OSAX() url = sa.the_clipboard() print url short_url = shorten(url) sa.set_the_clipboard_to(short_url) print short_url if __name__ == '__main__': shortenReeder() sys.exit(0)
- I used to post a reasonable number to Twitter as well. However I find myself engaging with Twitter less and less. Right now I mainly scan over my political feeds there to see what interesting articles are linked to. One surprising and disappointing feature of the ADN user base is how many use it just as a Twitter clone. Really it’s strength is in it being much, much more conservational. However not that many use it that way. ↩