Rubyfocus

Rubyfocus is a library with a simple goal: to provide a bridge between ruby and OmniFocus. Rubyfocus provides a pure ruby, application-independent interface to Omnifocus’ task database. Unlike JROFBridge, my previous OmniFocus bridge library, this library doesn’t bother talking to the OmniFocus application: instead, it talks to OmniFocus’ local library directly. This means that applications using Rubyfocus don’t care what version of OmniFocus you’re using, or even if OmniFocus is running: all they care about is that the library exists on your hard drive.

The main limitation on Rubyfocus is that it’s read-only: right now you can’t make changes to your tasks in OmniFocus, just read all the data out. It’s conceivably possible to edit, create, and delete objects in OmniFocus’ database, and maybe in the future I’d be interested in exploring that: for now, however, read-only is a pretty good start.

How do I use this library in ruby?

This library is distributed in the form of a ruby gem; however, right now it’s not registered on Rubygems. This means that you can’t just install it from the command line.1

Installing through git

This is the recommended way. Open your terminal, navigate to somewhere you’d like to place the code, and grab the source from git:

1
git clone https://www.github.com/jyruzicka/rubyfocus.git

Now build and install the gem:

1
2
3
cd rubyfocus
gem build rubyfocus.gemspec
gem install rubyfocus-0.1.0.gem

Download and install

If you don’t want to use git, visit the github page, download the code, and proceed to build and install as above.

How do I use this library in ruby?

To include the gem in your package:

1
require "rubyfocus"

If this is the first time your program is running, you’ll have to create a new Rubyfocus Document and update it from the local OmniFocus database:

1
2
3
f = Rubyfocus::LocalFetcher.new
d = Rubyfocus::Document.new(f)
d.update

You can save this to a yaml file, so you don’t have to start from scratch next time:

1
2
3
d.save("of-database.yml")

new_doc = Rubyfocus::Document.load_from_file("of-database.yml")

Here’s a snippet I tend to use at the start of most Rubyfocus programs:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
require "rubyfocus"

database_file = "of-database.yml"

d = if File.exists?(database_file)
    Rubyfocus::Document.load_from_file(database_file)
else
    Rubyfocus::Document.new(Rubyfocus::LocalFetcher.new)
end

d.update
d.save(database_file)

# Rest of program goes here.

For more information on what Rubyfocus can do, check out the readme.


  1. This will change in the near future, no fear!