The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus 1 for Mac (http://forums.omnigroup.com/forumdisplay.php?f=38)
-   -   AppleScript for moving mail messages to OmniFocus is creating duplicates in OmniFocus (http://forums.omnigroup.com/showthread.php?t=31118)

derekvan 2013-12-20 06:02 PM

AppleScript for moving mail messages to OmniFocus is creating duplicates in OmniFocus
 
I'm trying to customize [URL="https://github.com/HunterHillegas/OmniFocusMailFlags"]this script[/URL] 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[/CODE]

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.


All times are GMT -8. The time now is 05:08 PM.

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