Post to WordPress from Ulysses update 5/20

I’ve made a significant update to my app Post to WordPress for Ulysses today.

I’ve improved it so that there’s no need to edit the Automator app or need two parts (app & code file) for everything to work. The blog information (user name, password, URL, and SSL preference) is now stored in a separate file. Also, all the posting code is now inside the app, and the user doesn’t need to create a ~/bin folder to keep the Ruby code file in.

The ReadMe file has all the updated information and the install will be much simpler.

Even though Ulysses is beta testing a WordPress posting feature, my solution will work with the current version. I’ve also tested it against the beta, and it works the same. The one thing I like most about my app is that it converts any links into ones that open in a new window. There’s no way for this to be done in Ulysses, and having to do it manually in WordPress is tedious at best.

I’ve also decided to quit fighting with WordPress about how it interprets timezones. Posts uploaded with the app will now be plain drafts instead of scheduled posts.

Tech note

The reason I originally split the app into two parts was a text encoding problem. When Ruby was called from inside the Automator app, it wanted US-ASCII text and the UTF-8 text that Ulysses outputs would make it choke. My solution was to use the Bash shell inside the app to call the Ruby script. That way I could pass the encoding argument in the shebang line like this:

#! /usr/bin/env ruby -E UTF-8:UTF-8

This line will be ignored when using Ruby code inside of an Automator app. Automator calls Ruby directly and the shebang line (and any # encoding: lines) are ignored. That’s why I used the app to run a shell to run a script. Not ideal but it worked.

So how did I fix it? Turns out it was pretty damn simple. I just had to tell Ruby that the text it was getting was encoded in UTF-8 when it was reading the file. Not when the app was loading Ruby. I just had to update the ARGF line with the proper encoding.

ARGF.set_encoding('utf-8').each_line do |line|

With this in place, I could stuff all the code into the app and not need a script file tagging along. Plus I know it’ll work, because the only file it needs now is the password file. I also updated the error messages so if something breaks it’ll be easier to locate.

Hopefully these changes will make it easier for people to install the app.