So I found this article by Hunter Hillegas where he posts an AppleScript for taking flagged messages in Mail.app and adding them into OmniFocus. What I'd like to do is change this to look in all my Trash/Archives for flagged messages. The way that I work is that I'll flag a massage then delete it so that it's moved out of my inbox. I'll still see it in the Flagged mailbox in 10.8. Not sure if you can edit this to scan the Flagged mailbox or if it need to be modified to scan the Trash/Archive/All Mail folders.
Cheers for any help.
on run
tell application "Mail"
repeat with _acct in imap accounts
--Look For Flagged Messages in the INBOX
set _acct_name to name of _acct
-- I've tried changing "INBOX" to "TRASH", "FLAGGED", "TRASH MAILBOX", "ALL MAIL", etc, nothing seems to work :(
set _inbox to _acct's mailbox "INBOX"
set _msgs_to_capture to (a reference to ¬
(every message of _inbox ¬
whose flagged status is true))
repeat with eachMessage in _msgs_to_capture
set theStart to missing value
set theDue to missing value
set theOmniTask to missing value
set theTitle to the subject of eachMessage
set theNotes to the content of eachMessage
set theCombinedBody to "message://%3c" & message id of eachMessage & "%3e" & return & return & theNotes
tell application "OmniFocus"
tell default document
set newTaskProps to {name:theTitle}
if theStart is not missing value then set newTaskProps to newTaskProps & {start date:theStart}
if theDue is not missing value then set newTaskProps to newTaskProps & {due date:theDue}
if theCombinedBody is not missing value then set newTaskProps to newTaskProps & {note:theCombinedBody}
set newTask to make new inbox task with properties newTaskProps
end tell
end tell
set flagged status of eachMessage to false
end repeat
end repeat
end tell
end run