OmniFocus 2 for Mac & Scripting

AppleScript support in OmniFocus 2 is a Pro feature—it’s extremely powerful. AppleScript is a programming language that interfaces directly with features of an application; it allows for manipulation of data or interface elements in apps that add support for it.

OmniFocus 2 has improved AppleScript support but should work with older, already-compiled scripts. Now that OmniFocus lives in a sandboxed environment, though, it’s worth taking a look inside and making some basic changes to bring ‘em all up to date. Get familiar with OmniFocus 2 AppleScript changes here.

If you do run into a problem with a specific script, check these changes first. If there’s a bug, let us know.

Using JavaScript for Automation in OS X

In OS X v10.10, JavaScript was added as an alternative to AppleScript. There’s a must-read site full of documentation about the addition.

The resources listed here don’t yet incorporate JavaScript.

Pretty Common Stuff

Actually, common is a bit of a misstatement! If you can dream it, you can probably achieve it with AppleScript and some glue. Starting with something simple like moving a due date forward by two weeks with the click of a button, to the advanced: generating a PDF of all completed, flagged actions in the last few weeks and emailing it to a partner or manager. (And then this thing and that thing and maybe a thing or two more…)

Folks have added entirely new features to OmniFocus: Curt Clifton’s Populate Template Placeholders script (and Chris Sauves own implementation, a script to find actions from a particular sender in your database from Mail, for deferring, for support documents, etc.

Helmut wrote quite a bit on deferring tasks quickly, made a mashup with a few other scripts, and paired it with Alfred. Massively convenient and all backed by AppleScript.

This won’t be a tutorial or a walkthrough on the entire OmniFocus 2 AppleScript library, but you will get a few examples of the flexibility.

Getting data into OmniFocus

Some people use OmniFocus for everything; here’s an “everything” example:

tell application "Radium"
    set actionTitle to "Listen to more " & track name
    tell application "OmniFocus"
        tell default document
            parse tasks into it with transport text actionTitle
        end tell
    end tell
end tell

Radium is an internet radio player that lives in your menubar. Anytime a new, interesting song is played, running this script will add it to your Inbox for later. It’s up to you to process later, but it’s a good example of adding an action via AppleScript.

AppleScript results of the above script.

Views

Switching views quickly is super easy with the new Quick Open feature in OmniFocus 2. Hit ⌘O, start typing where you’d like to go, and WHA-BAM: you’re there. (After you hit return.)

But you can incorporate switching, opening, and adding views to your workflow just as easy with AppleScript. (It’s even more useful with a systemwide quick-launcher like Launchbar, Alfred, or Quicksilver!)

Here’s how to activate a perspective in your frontmost window:

tell application "OmniFocus"
    tell the default document to tell the front document window
        set perspective name to "Review"
        activate "OmniFocus"
    end tell
end tell

You can also open that up in a new window so you don’t mess with your current window’s configuration:

tell application "OmniFocus"
    tell default document
        make new document window with properties {perspective name:"Review"}
        activate "OmniFocus"
    end tell
end tell

If you do use Launchbar, just put those scripts in your ~/Library/Application Support/Launchbar/Actions/ folder. You could then open a new perspective window from wherever you are.

A Sandboxing Note

Remember, a requirement to being in the App Store is sandboxing: making sure the application cannot touch anything else on the system you haven’t explicitly given it permission to touch. You can continue to install scripts that live in your toolbar at a specific spot:

~/Library/Application Scripts/com.omnigroup.OmniFocus2

You can get there quickly by heading to Help->Open Scripts Folder.


Further

Mail

Adding Actions

Acting on Actions

Templating

Other!

Know of something worth including here? Send ‘em our way: inside@omnigroup.com