29 11 / 2011

Textmate to Tumblr

I went looking for a way to post to Tumblr via the command line the other day, and I was very interested in M. Wunsch’s post. He has created a Ruby gem which elegantly speaks to the Tumblr API and creates posts with attributes specified in a YAML front matter, a la Jekyll. This is brilliant, and wonderful. A really good idea sparks other ideas, and this one sent lightbulbs off in my head. I could use this to create a script that would automatically post to Tumblr, or even better I could use the still fabulous Textmate to make a bundle that would make my blogging just a few button presses away. Seems wonderful.

Now a few brief words on why anyone would ever want to go to this trouble. Isn’t there a nice little text box on the Tumblr post screen that would do this for me?

I could just enter my posts that way, and hey, I can even write them in Markdown! Off the top of my head, here is why I would want to do this.

  • Have a copy of every post I ever made in an easily readable, renderable format
  • Luxury of writing in my favorite text editor
  • No suffering from closed tab syndrome (ask my wife, who posts from a Wordpress entry form)
  • Able to write posts even when Tumblr is down (hey it has had more uptime than me recently)

Some of these need no explanation. I cannot emphasize enough how nice it is to have the ability to compose in my own editor, with its over abundance of tricks and hacks that I have built up. So, on to the how-to.

This is taking place on a Mac. Primarily because that is where you can use Textmate. Now the first part would be equally viable on any Linux Ruby install. Install the gem:

sudo gem install tumblr-rb

That builds it out and installs the tumblr executable. You can check the extensive documentation on how this CLI tool works on M. Wunsch’s excellent github page. The flexibility of the tool is truly excellent. Many modes are supported. However, it is fairly simple to use to setup a Textmate bundle. First create a file in your home directory to store your Tumblr credentials.

mate ~/.tumblrcreds

Enter your username and password as such

username: YOURuserNAME
password: myCRAZYAWESOMEsecurePASS

Please substitute your own combination. And email me if that really is your password cause that is epic. Do not tell me to what it is your password. Now in Textmate open up your bundle editor, available in Bundles -> Bundle Editor -> Show Bundle Editor. Create a new bundle using the plus sign at the bottom. Use these settings as a guide.

If this is done correctly, it will take the entire document and feed it into the tumblr command line utility. The command line utility, using the file we created earlier for reference, posts your document to Tumblr. If there is any feedback, it will provide it to you in a fresh document in Textmate. Now you are just a key combination away from a fast Tumblr post. It even supports queued posts with specified publish times, if you are one of those real bloggers that has several posts in the queue ready to go.

Let me know how it works for you!