I have really been having good luck using OmniFocus and Getting Things Done to keep my life in order. One thing I like that OmniFocus provides out of the box is a way to automatically process email sent to a specific address and add it to OmniFocus. I have even provided this address to family and friends so they can automatically add tasks for me to review. Whether or not you want others to have this ability is a different question.

However, sometimes there are emails that I want added to my OmniFocus Inbox that come from other places, and I was not able to find an easy way to do that. I really had few requirements:

  • The subject was used as the task name.
  • The note contained a link to the original email message.
  • The message would be moved to my “Archive” folder.

I could have chosen to include the contents of the message in the note field, but a link seemed easier because there could be attachments, long signatures, an entire thread, etc. My solution was to create a service in Automator that uses a simple AppleScript.

The quickest way to get going is to clone the script into ~/Library/Services:

git clone https://github.com/nlindley/mail-to-omnifocus.git ~/Library/Services/Send\ to\ OmniFocus\ and\ Archive.workflow

You can then highlight the messages in Mail that you would like to send to OmniFocus, click on Mail in the top-left of the system menu, go to Services, and click Send to OmniFocus and Archive. Since I don’t like using a mouse much of the time, I created a keyboard shortcut in System Preferences.

The entirety of the AppleScript is below.

on run {input, parameters}

    tell application "Mail"
        set theSelection to selection
        set DestinationFolderName to "Archive"

        repeat with theMessage in theSelection
            set theSubject to the subject of theMessage
            set theURL to "message://%3c" & theMessage's message id & "%3e"

            tell application "OmniFocus" to tell default document
                make new inbox task with properties {name:theSubject, note:theURL}
            end tell

            set theAccount to account of mailbox of theMessage
            if name of every mailbox of theAccount contains DestinationFolderName then
                set archiveFolder to mailbox DestinationFolderName of theAccount
                move theMessage to archiveFolder
            end if

        end repeat
    end tell

    return input
end run
Nicholas Lindley