Import Mail.app “Notes” Into Evernote

February 25th, 2009  |  Published in ruby  |  20 Comments

  • Updated 12/16/2012 to add a contributed AppleScript to import notes from Mountain Lion’s Notes.app to Evernote

  • Updated 5/25/2010 to add the creation date of the Mail.app note to the imported Evernote item.

Mail.app has these things it can store called “notes.” Along with mail-based todos, they’re meant to turn Mail.app into more of a productivity hub. I don’t have a strong opinion about them, mostly because they’re an absolute nightmare if you make the mistake of letting them come near a Gmail account, which I did. The experience was unpleasant enough that I never decided whether I liked them away from a Gmail account or not.

Another weird thing about Notes from a scripting perspective is that when they aren’t tied to an e-mail account, they don’t seem to exist in any way you can get at them if you store them in their little “Notes” hierarchy. Mail.app’s scripting dictionary doesn’t acknowledge the existence of a specific class of things called notes, and scripts don’t find anything inside the folders holding them. AppleScripts trying to talk to the mailbox “Notes” compile but don’t do anything. appscript scripts claim that they’ve got a reference to the mailbox, but return an empty array when you ask for the items within.

Someone on the Evernote forums, however, had a good enough experience with them that he had 400 he wanted to move from Mail.app into Evernote (so I guess the experience wasn’t that great in the end). Like I said, I don’t even care about notes, but I did think “I’ve already done that with messages in Evernote, so I’m sure I can easily repurpose that.” That’s when I discovered the existenceless existence of Notes.

It turns out, though, that you can just make a new mailbox on your Mac and drag all your notes into it, at which point they become messages for purposes of scripting them. The first line of the note is the “message” “subject,” and every line of the note including the first is the “message” “content.”

Once I had that worked out, it was easy to mass import a sample of test notes into Evernote:

I ended up deciding to do it in Applescript when I realized Ruby probably would not be helpful to the original poster. If you count the shebang and require lines, it took 18 more characters in Ruby than in AppleScript.

Here’s another one, contributed in the comments by Lee, for using the new Notes.app found in Mountain Lion:

  • http://veritrope.com Justin

    Hi Mike,

    Your script inspired me to make a “Apple Mail to Evernote AppleScript” of my own: http://veritrope.com/tips/mail-to-evernote

    Kind Regards, Justin

  • http://nomulous.com/ Fletcher Tomatly

    Worked perfectly, thanks so much!

  • http://www.heynanynany.com trav

    this is fantastic thanks!!!

  • Sergio

    Thank you!

  • Orlando

    Would it possible to add a step by step of this process for people who never wrote an applescript before? Thanks.

  • Christopher John Shaker

    Worked great for me, except that it created some very long note titles. This broke Evernote, it would not sync. Gave me ‘Evernote Multiple validation errors occured.’ I selected all of my notes and then exported them to an Evernote file before I exited the program. Good thing I did, because only three of my notes made it to the Evernote server.

    The longest title Evernote supports is 255 characters long. The program isn’t smart enough to check it and warn you about it! Some of my titles were one paragraph long!

    Once I edited the note titles and trimmed them down to size, Evernote synced my messages just fine.

    Help for those who’ve never run an Apple Script before:

    o Create a new mail folder called “NoteMigrate” o Select and copy all of your Mac Notes. Paste them into ‘NoteMigrate’ o Go into Applications/Utilities o Open the ‘AppleScript Editor’ o Copy and paste the apple script above into the top window o Click ‘Run’

    That did it for me. Chris Shaker

  • Søren

    Thanks – worked like a charm, very easy and elegant. Saved me a ton of work.

  • http://zeus.azc.uam.mx/juanvc/ Juan

    Thank you, it works perfect!

  • Rachael

    worked first time round and was worth all the research made to find it

  • http://twitter.com/andycaster Andy Bilodeau

    Even 3 years later, this applescript worked flawlessly. woo hoo. thanks for posting this!

  • Lee

    Pretty cool; thanks. Updated for new Notes app in Mountain Lion:

    tell application “Notes” set theNotes to every note of the folder “Notes”

    repeat with thisNote in theNotes
        set myTitle to the name of thisNote
        set myText to the body of thisNote
        set myCreateDate to the creation date of thisNote

    tell application "Evernote"
        create note with html myText ¬
            title myTitle ¬
            created myCreateDate ¬
            notebook "Imported Notes"
    end tell
    

    end repeat

    end tell

  • http://m.pdbl.org/ m. hall

    Thanks, Lee! I’m going to put that in a Gist and embed it above, if you don’t mind.

  • Alex S

    Thank you very much! You just made my day!

  • Dave

    Anybody monitoring this still? I am getting an error and would like some help with the ML script. Here is the error:

    An internal database error has occurred that prevents Evernote from functioning properly. If the problem persists, please contact Evernote Support.

    I am using it exactly like it is posted above.

    Thanks!

    Dave

  • http://m.pdbl.org/ m. hall

    Hey, Dave,

    I still live here, so I guess it’s monitored. :-)

    Which version of the script is throwing this error? The AppleScript version that uses Mail notes, the Ruby version, or the AppleScript version that uses the Notes app?

  • zhubochubo

    Hi m.Hall: thankyou for this great script. I know what the cause of Dave’s problem is, because it’s the same with me — evernote doesn’t like titles longer than 255 characters. I wonder, is there a way to modify the “set myTitle to the subject of thisMessage” line so that the title is set to be only the first 255 characters of the “subject of thisMessage”?

    If not, Dave, one way around it is to flick through your notes and add a break when the first line is really long. However, this does have the disadvantage of changing the “Date Received”, and therefore the “Created” field in Evernote, to today’s date.

  • zhubochubo

    no ideas on this?

  • http://twitter.com/sowenjub Sowenjub

    4 years later and it’s still useful, thanks a lot :) I forked your gist and added export of the modification date as well https://gist.github.com/sowenjub/5138539

  • David Payette

    Really, really helpful. Thanks.

  • http://twitter.com/nellosacco Nello sacco

    From Bologna Italy A great great great thank you

© Michael Hall, licensed under a Creative Commons Attribution-ShareAlike 3.0 United States license.