Export Apple Mail Messages and Notes to Text Files

I saw a Tweet from Scott Paterson, asking if there was an AppleScript to quickly batch export Notes from Apple Mail into individual text file.

Well Scott — If there wasn’t one before, there is now!

Features

  • This AppleScript will export any selected Messages or Notes in Apple Mail as individual text files to a temporary folder on your Desktop (called “Temp Export Folder”);
  • The script also attempts to remove any “illegal characters” from the file name as to avoid the process grinding to a complete halt!
  • If you have Growl installed, the script should detect it and notify you when your export is completed.

Current Limitations and Open Issues

(Otherwise known as “Places Where You Could Help Out!”)

  • I kept the output very basic — only spitting out the content of the note/message as the content of the text file. It *IS* possible to add more information from the messages and, if people are interested in that, let me know!
  • Errors that will undoubtedly arise when you do something that I didn’t think of or test for! 😉

How to Install and Use

As of Version 1.1, the source code and instructions are moving to the Veritrope.com Code Library:

CLICK HERE TO GET THE SCRIPT AND SEE THE SOURCE CODE!

Found a bug in the script?

Click Here To Submit Your Bug Report!

Interested in what other AppleScripts are available on Veritrope.com?

Click here to see the latest list!

22 Responses to “Export Apple Mail Messages and Notes to Text Files”

  1. ukmac (Scott Paterson ) January 31, 2010 at 5:02 pm #

    Twitter Comment


    Thanks to @veritrope for knocking up AppleScript to export Notes to text files from Mail.app [link to post]

    Posted using Chat Catcher

    • D May 17, 2010 at 5:19 am #

      Thanks for putting this together. Two things: 1) Can I have the original dates exported with the notes? 2) The script fails because it requires Growl which I don’t have installed (I don’t really have a need for Growl). Do you have a version of the script that doesn’t need Growl?

      • Justin Lancy May 22, 2010 at 10:09 pm #

        The Growl issue must be a bug — it’s supposed to detect whether or not you have it installed and adjust. Click here to file a bug report so that I don’t lose track of it and, when I’m working on a new revision, I’ll spend some time on this!

        A question: How would you want the original dates presented? As a header at the top of the note?

        • lydia July 3, 2010 at 7:46 pm #

          for me, it would be useful to have basic messages headers placed at the top of each txt file. would love to see at least “From:”, “Subject:”, and “Date:”. would that be easy to add if i knew what i was doing?

          (i am about to take off on a big trip, am trying to create an archive of the relevant mail folder, don’t really have time to delve into learning applescript just now.)

  2. Danny July 5, 2010 at 2:31 am #

    You just saved me about an hour. Thank you.

  3. ERicb October 4, 2010 at 11:40 pm #

    Thanks !! Perfect for converting email to text so that the new (Dragon ) Dictate can learn writing style / vocab!! This saved me TONS of time / training…

    Thank you again!!

    EricB

    • Justin Lancy October 6, 2010 at 12:42 am #

      Thanks — and I think that’s a really great way to use this script!

      I’d love to use it the same way myself and I even reached out a few weeks ago to Dragon to send me a review copy so I could also try some direct scripting… Guess I’ll have to wait for them to offer that promised crossgrade from the PC version! 😉

      One way or another, I think I’ll have some Dragon scripts up sometime in the near future…. and if you come up with any of your own, please use the submission page to share them with all of us!

  4. Morgan October 17, 2010 at 6:44 pm #

    Thank you! Thank you! This is exactly what I needed!

    • Kevin November 6, 2010 at 10:54 pm #

      This was a very helpful tool, thanks! On my Mac running 10.5.8, I commented out the 32-character filename limit, removed the illegal character filter (except “:”), and removed the “.txt” filename suffix. Then I was able to use it to export 600 Notes from Apple Mail to the temp folder, then import everything in that temp folder to my Mark/Space Notebook then synchronize them into the Fliq notebook app on my Samsung Galaxy S Captivate (Android 2.1) using The Missing Sync for Android. Whew!

      It would be nice to have parameters at the top of the the script to choose the file naming validation based on the operating system.

      • Justin Lancy November 6, 2010 at 11:08 pm #

        That’s an interesting idea, Kevin… let me play around with some ways to do that!

  5. Hans Erik January 16, 2011 at 4:36 pm #

    Hi Justin,

    This certainly is a timesaver.
    One problem I encountered: whenever two messages have the same name, the first is written over by the second. So I took a deep breath and changed the a little, by adding a counter, that is attached to the filename:

    set msgnr to 1
    ...
    repeat etc.
    ....
    set theFilePath to (SaveLoc & msgnr & "_" & theFileName & ".txt")
    set msgnr to msgnr+1
    end repeat

    etc.

    Hans Erik

  6. Rick Bennett February 21, 2011 at 2:04 pm #

    This little script saved my bacon. Man, I think it’s crazy that Apple doesn’t have an “export messages” button under their Mail/File menu.

    • Justin Lancy February 21, 2011 at 2:18 pm #

      Mmmm… BACON!
      😉

      Seriously though — Glad it was of help to you, Rick!

  7. albarn September 17, 2011 at 2:59 am #

    why do you have to prefix the text files with number and underscore?????

  8. albarn September 17, 2011 at 3:04 am #

    nevermind.. i’ve removed your portion of code that adds the prefix.

    • Justin Lancy September 17, 2011 at 3:11 am #

      Being able to tweak this stuff to your preference is one of my favorite things about AppleScript — glad you sorted it out! 😀