I'm trying to customize
this script to import all flagged mail messages in Mail.app to Omnifocus, then unflag and archive the message. It works, but it creates many duplicates in the Omnifocus inbox for some reason.
Here's the script:
Code:
on run
tell application "Mail"
set _inbox to "INBOX"
set _msgs_to_capture to (messages 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
move eachMessage to mailbox "Archive" of account "memoryfailure"
end repeat
end tell
end run
I don't know the first thing about applescript, so any pointers would be great. I've tried cobbling together a few ideas from scripts I've seen in various places, but I seem to be missing something here that's creating duplicates.