Apple Mail.app to ToodleDo


I already had one script that would send the current message to ToodleDo, but I wanted to adjust it somewhat, so I could flag messages instead, and have them exported, either on a schedule or by hotkey.  I reserved the yellow flag in Mail.app for “New Tasks” (you can rename the flags in the sidebar you know) and reserved the green flag for “In Progress”.

I wrote/stole parts of this script:

tell application "Mail"

    repeat with myAcct in imap accounts
        -- Store the account name - not used here, but hey.
        set theAccount to name of myAcct
        set myCustomToodleDoEmail to "Add it [email protected]"

        -- I have multiple accounts with the same messages for backup,
        -- but I only want to choose the GMail ones...
        if "GMail" is in (name of myAcct as string) then

            -- Here's where I could have had it search all mail, and then
            -- I could archive messages first, export later.  I may still do this.
            -- set theInbox to myAcct's mailbox ("[Gmail]/All Mail")
            set theInbox to myAcct's mailbox "INBOX"

            -- Flags are numbered from 0=Red on up
            set theMsgs to (every message of theInbox whose flag index = 2)

            repeat with eachMsg in theMsgs

                set theTitle to the subject of eachMsg
                set theNotes to the content of eachMsg

                -- This next one isn't used, but was useful for debugging.
                set theFlag to eachMsg's flag index as string

                set messageURL to "<a href='message:%3c" & (message id of eachMsg) & "%3e'>" & theTitle & "</a>"
                set theBody to messageURL & return & return & theNotes

                set theNewMessage to make new outgoing message with properties {subject:eachMsg's sender & " " & eachMsg's subject & " ! *INBOX $Planning", content:theBody, visible:true}

                tell theNewMessage
                    make new to recipient at end of to recipients with properties {address:myCustomToodleDoEmail}
                    send
                end tell

            end repeat

            repeat with eachMsg in theMsgs
                set flag index of eachMsg to 3
                -- Could also unflag - more useful if you archive first
                -- set flagged status of eachMsg to false
            end repeat

        end if

    end repeat

end tell

There are some unused things in there, I didn’t want to take them out, instead just leave them in for reference just in case I change it later.  I have this bound to a Mail Act-On keystroke, but I may change it to a iCal alarm so that it pulls out the tasks a couple times a day.  If I do this, I will change it so that it looks in all mail and I can archive immediately after tagging.  It will clear my inbox and still let me track tasks effectively.

If you use this or it helps, please let me know!

,

Leave a Reply