The PERL Way to Add OmniFocus Inbox Entries from Twitter

Posted on 3 minute read

× This article was imported from this blog's previous content management system (WordPress), and may have errors in formatting and functionality. If you find these errors are a significant barrier to understanding the article, please let me know.

Over the weekend I got the bright idea of asking OmniGroup to ask an iPhone voice recognition application (like Dragon Dictation) to add a link to the OmniFocus iPhone application. That way I could simply dictate new inbox items on the iPhone rather than laboriously typing them with the on-screen keyboard. Before making the suggestion, I searched the OmniFocus User Forum for "voice recognition" to see if anyone else had suggested the same thing. As it turns out, there were a few posts that had instructions from people using Twitter as an intermediary. Unfortunately, they either required a desktop Twitter client to be running all of the time or used the now deprecated BasicAuth-based Twitter authentication scheme. So I created my own.

The Script

I'm a UNIX command line geek at heart, and an old one at that, so my preferred language is Perl. This program runs as a background command line application using a couple of Perl modules: Net::Twitter::Lite to interact with Twitter and Mac::AppleScript to interact with OmniFocus. Install those two modules and their depencencies on your Mac if you don't already have them (e.g. cpan install Net::Twitter::Lite and cpan install Mac::AppleScript), then copy this script and a configuration file based on this sample in a directory off your home directory. The source code is available on GitHub if you want to fork it and improve it.

Registering your Application with Twitter

[caption id="attachment_1735" align="alignright" width="300" caption="Tweet Privacy Checkbox"][/caption]To put Twitter in the middle between my iPhone voice recognition app and OmniFocus, I set up a new Twitter account just for the purpose of pushing entries into the OmniFocus Inbox. I marked this new account as private in the account settings because I don't want anyone subscribing to the tweets sent through this account.

Because I marked it as private, the script can't read the home timeline of tweets without authentication. In order to authenticate with Twitter, I need to register the script with the Twitter API service to get a "Consumer Key" and a "Consumer Secret". The registration page looks similar to below, but you'll need to pick a different name. (Application names must be unique across Twitter.)
[caption id="attachment_1737" align="aligncenter" width="795" caption="New Twitter Application screen for twitter-to-omnifocus"][/caption]

After submitting that form, you'll see a page that will have your key information. Replace the sample keys in the tweettoOmniFocus.cfg file with the ones from this page.

You'll need to run the twitter-to-omnifocus application once interactively on the command line in order to complete the process of registering the script with Twitter. First, change the mode of the script so that you can execute it, then run the script:

  chmod u+x twitter-to-omnifocus
  ./twitter-to-omnifocus

You'll be promted to go to a website to get a PIN:

  Authorize this app at http://twitter.com/oauth/authorize?oauth_token=nnn and enter the PIN#

When you get the PIN, paste it into the terminal window and hit return. Two new security tokens will be added to the configuration file.

Getting the Script to Run Periodically on the Mac

The last step is to get the script to run periodically on the Mac. If one were to stick to UNIX traditions, you would run `crontab -e` to create a cron entry. I think that would work, but the Mac-way of doing it is to create a launchd entry. You can create one of these by hand, but I find using Lingon to be a much more palatable way of doing it. (Okay -- so I'm not a pure command-line junkie.)
[caption id="attachment_1738" align="aligncenter" width="714" caption="Lingon configuration for twitter-to-omnifocus"][/caption]

All Done!

[caption id="attachment_1742" align="alignright" width="200" caption="iPhone Dragon Dictation screen"][/caption]With that set, you can now simply send a tweet to your private Twitter account from any mechanism you might have. What got me started on this path was using Dragon Dictation on the iPhone to dictate inbox items. One person suggested using Jott for phone-to-Twitter transcribing and another suggested an e-mail path.

In the end, this is quite an effort and a moderately fragile setup for doing what I want. In particular, the dictated entries don't immediately appear in my iPhone OmniFocus app database. I'd like some tighter integration between the applications, but I'll settle for this for now.