The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Help? Send flagged messages to Omnifocus automatically, changing title/context based on from/subject (http://forums.omnigroup.com/showthread.php?t=26245)

jpr 2012-10-15 03:08 PM

Help? Send flagged messages to Omnifocus automatically, changing title/context based on from/subject
 
1 Attachment(s)
Hello. Been working on a project for a while and can't figure out a way to do this reliably. I've been using this Applescript (won't let me post URLs: hanchorllc.com/2011/12/11/omnifocus-task-auto-import-via-ios-mail-flags/) to send flagged messages to Omnifocus, but the implementation is a little dumb. I'd like to be able to change the title and context of a task based on who's from or subject. I've sort of brute-forced this by making different Applescripts for each rule I want and making it run when getting the specified email.

I'll explain the use, I feel I'm being obtuse: I live on a college campus and use email for a ton of notifications (eg. package received at campus mail room, book ready to be picked up from library). I have my Macbook constantly running in my dorm, collecting these emails and ready to send them to Omnifocus, so for example I can look at the iPhone version of Omnifocus and see I should stop by the mail room to get my package while I'm out. Another use is Kickstarter "Response needed!" emails: I'd like to catch these and throw them into my Internet context.

What I've done is make a bunch of mail rules that automatically flag an email from, for example, the campus mail room, then run the appropriately edited above Applescript which throws an Omnifocus task with the "Mail Room" (or "Library," or "Internet") context and "Pick up package from mail room." (or "Pick up book from library," or "Respond to Kickstarter." title, with the body of the email in the notes section. This would work fine, except when I inevitably receive a mail room and a library email and the rule runs and there are either unnecessary or incorrect duplicate tasks made.

Is there a way to get the subject/from part of a flagged email in Applescript then change the title or context of the task accordingly, and do so for each flagged email? I can't figure it out.

I'm sure this could be applied to anyone who gets similar high priority emails. Thanks for any help, and if I'm at all unclear or obtuse please let me know. I'll clarify. Really looking for a solution.

Attached is an example of one of the Mail rules I use.

jpr 2012-10-15 07:24 PM

1 Attachment(s)
Spent some time figuring it out myself, here's how for those that find this thread.

First make a mail rule that collects the messages you want it to collect. I've attached a screenshot of one of mine.

The "Amazon Order Shipped" script is this:

[CODE]using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
set theMailCount to (count of theMessages)

repeat with counter from 1 to theMailCount
set msg to item counter of theMessages
set theAttachmentCount to (count of mail attachments of msg)
set _title to subject of msg
set _sender to sender of msg
set _notes to the content of msg

set _combined to "message://%3c" & msg's message id & "%3e" & return & return & _title & return & return & _notes

tell application "OmniFocus"
tell default document
set theContext to (first flattened context where its name = "Computer")
set newTask to make new inbox task with properties {name:"Add tracking number to package tracking application.", note:_combined, flagged:true, context:theContext}
end tell
end tell

end repeat

end tell
end perform mail action with messages
end using terms from[/CODE]

This can be really, really easily modified for almost any use that involves collecting emails. I've made multiple Applescripts for each use of mine, changing appropriately this part:

[CODE] set theContext to (first flattened context where its name = "Computer")
set newTask to make new inbox task with properties {name:"Add tracking number to package tracking application.", note:_combined, flagged:true, context:theContext}[/CODE]

To whatever context and title I want.

Pretty simple stuff, but hope this helps someone.


All times are GMT -8. The time now is 04:53 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.