Alfred Script for auto forwarding email to OmniFocus

Hey. I searched for a long while trying to find a single action way of forwarding emails to the OmniFocus inbox. I don’t know why, but there was just a little bit of resistance in having to Cmd-F the email, try to get the to field to auto-recognize the omnifocus forwarding address, and edit the subject as needed.

I finally just broke down and tried to write this myself. I’m terrible with AppleScript, so I’m sure there this can be improved.

Using Alfred I wrote a workflow that take a keyword (I used “fo”) with an optional argument. The keyword invokes the following Applescript:

on alfred_script(q)
    set alfredSubject to q
    tell application "Mail"
        set messageThread to the selection
        set theMessage to the last item of messageThread
        set theAccount to the name of the account of the mailbox of theMessage
        set newMessage to make new outgoing message at end of outgoing messages
        tell newMessage
            set content to (theMessage's content as Unicode text)
            if alfredSubject is "" then
                set subject to theMessage's subject
            else
                set subject to alfredSubject
            end if
            make new to recipient with properties {address:"myOmniFocusInbox@sync.omnigroup.com"}
        end tell
        move theMessage to mailbox "Archive" in account theAccount
        send newMessage
    end tell
end alfred_script

If there is no argument after the keyword, the email is forwarded using the existing subject. If there is an argument then it uses that argument as the subject.

Note that because of the threaded nature of messages in Mail.app, Applescript understands selected emails as a list. Since you have to select one, I selected the last, which if you accidentally select a message thread is usually the intended one.

Anyhow, it was driving me nuts that I couldn’t find this somewhere on the internet. Let me know if there is a better one that I just missed, or if not, are there are any suggested improvements to this one.

Did you add this to Packal?

I don’t use Omnipresence to forward emails so I may be missing something here. if you are using a personal Mac which also has Omnifocus, why not just parse the email with Applescript and create a new item in Omnifocus with it? You are partly there already, and you can set it up to use values that you usually use as defaults.

Second, this is basically just forwarding the email to a different address - it isn’t saving you much time over tapping ‘forward’ in Mail and typing a few letters of the forwarding address and maybe adding a title. You could make an Applescript with some minor GUI scripting to accomplish most of that which gives you the option of changing the Subject — but even that offers little in ‘time saved’.

Maybe the reason you couldn’t find a pre-existing applescript for this is that it wasn’t something that vastly improved on other already available options?

I thought about posting it to Packal, but it doesn’t quite feel polished enough for that.

I mean I’m not sure what you want. I literally said exactly this in the very first line of the description. I like one-click solutions.

If you have any Applescript examples that parse new projects directly into the inbox or project list, I’d like to see them.

You’ve got the basics of parsing a mail message for all its components. It is just a matter of directing them to OF. I don’t have any scripts that do this particular thing, but I do have one I use which creates a new event in OF which sets a reminder for me to check my paystub for a mileage reimbursement every so often which looks like this:

tell application "OmniFocus"
tell its document "OmniFocus"
	tell its project "Work"
		make new task at end with properties {name:"Travel Miles Reimbursement received in Pay stub?", due date:reminderdate, note:"should be for $" & totalDue}
		-- can't set a notification using AS????
		
	end tell
end tell

end tell

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.