Using Google Apps Script to Automatically Email Tasks to OmniFocus

Fair Warning: This is definitely overkill for casual OmniFocus users. Only worth the time if have a lot of email where simply forwarding doesn’t provide useful task names (e.g. Fwd: Important Email) or where some processing would significantly improve the resulting Mail Drop task.

I spent a few hours the other day learning my first little bits of JavaScript and using it to build a Google Apps Script that sends tasks to OmniFocus by way of Mail Drop.

I intended it primarily for use with Gmail, with the big idea being automatic processing of specific, predictable patterns of emails into tasks. Simple forwarding to Mail Drop is great, and setting up IFTTT to watch a label (mine is called # Action so it floats to the top on iOS) is even better.

However, if the email has a predictable pattern, you can improve the process even more by automating the content of the task name and note (instead of manually rewriting or just settling for Fwd: Whatever Their Subject Was).

For example, if you get a monthly email about your water bill that follows a pattern like:

  • From:
  • Subject: New water bill
  • Body: Your new water bill for the month is $45.50

Manually forwarding to Mail Drop gives you a task named: Fwd: New water bill, with the actually cost in the note, which to me is less helpful than having a task named Pay August water bill: $45.50 with perhaps a link to the payment website in the note.

Using Google Apps Script looks like one way to accomplish this level of automation. You could even put tests in place that would only create a new task if certain criteria were met (e.g. the bill was over $50.00).

The basic process is:

  1. New email matches a Gmail trigger and gets a label.
  2. Google Apps Script runs ever 15 minutes or so, processes any new emails in the label.
  3. Rules in the script match the labeled email, based on your criteria (e.g. to:, from:, subject:) and trigger a custom function.
  4. The function processes the email however you choose, presumably resulting in sending a well formatted task to OmniFocus via Mail Drop.

If you’re interested, my script is hosted on GitHub here, and I posted a fairly detailed explanation here. Again, this really is overkill for most people, but I’m pretty excited about it and wanted to share.

One drawback is that Mail Drop doesn’t yet support parsing due dates / contexts / projects, so the tasks will end up in your inbox. My only thought for a way around this would be instead of using Mail Drop, to instead upload a text file to Google Drive, sync that file to your Mac with the Google Drive app, and use a folder action or Hazel to process the text file in AppleScript… messy.


This should work brilliantly with my current Gmail setup.

In case anyone is interested, I currently have a slightly modified version of this setup in Gmail:

I have modified this to use labels instead of flag icons (though the icons will still work). The reason for this is that the icons don’t work on mobile. I have 5 labels:

  • #Action - items that need me to act on. My todo list.
  • #Waiting - delegated tasks, and items i’m waiting for such as amazon packages
  • #Event - Any upcoming event that I am committed to or considering. Flight info. Concert tickets. Seminar info.
  • #ToReview - Articles, documents, videos, podcasts I want to read/watch/listen to that don’t require any response.
  • #Reference - Any other emails I need access too often.

Here are the rules I use:

Pane 0: label:#Action OR has:yellow-bang OR has:red-bang [Needs Action / Reply]
Pane 1: label:#Waiting OR has:purple-question OR has:orange-guillemet [Waiting / Delegated]
Pane 2: label:#ToReview OR has:green-star [To Read / Review]
Pane 3: label:#Event OR has:purple-star [Upcoming Events]
Pane 4: label:#Reference OR has:blue-info [Reference]

This did mean I had to completely disable priority inbox, but this system is WAY better anyway. I reach inbox zero daily with minimal effort, and I have an at-a-glance single-page view of all emails that are important.

1 Like