Mail Archive in Evernote

Hi there,
I am a noob, so please bear with me…

I would like to create a KM macro that does the following:

Print All Emails that are older than 1 year as PDF, and save to specific folder. If the email has attachments, save them in the same folder.

A Hazel script then picks this up once a day and saves it to a notebook in Evernote.

This way I have an archive of all my saved mail, but keep my email archive folders/inboxes lean (which means faster mail clients on mac and iOS)

What scripts/macros will I need to accomplish this?

Actually, I think I will try to do this without Hazel involved in the process, I realise it will probably involve a heavy dose of AppleScript, which I know little about…

Hey David,

Mail has no facility for scripting print jobs, so all the printing would have to be brute-force.

Mail since Mavericks has been iffy about scripting attachments.

Basically you’re better off spending money and buying Email Archiver Pro; you’ll end up with a better outcome. (There’s a demo.)

If you really want to tackle it with Keyboard Maestro and AppleScript you have a major job on your hands.


Hi Chris,

what do you mean by that?

Looking at it now. A similar one I have been testing is Mail Archiver X. But these software's both cost 40$. I would love to avoid spending the cash, was hoping KM would be able to achieve this...


This does not do exactly what you asked for, but it does move Mail to Evernote.
You might take a look at this script by Veritrope to see if it is of any use to you.
I have never used it, so I can't vouch for it.

Apple Mail to Evernote

He probably means that what you’ve done in the first version of your “Transcription” macro: building a chain of automated mouse clicks and keystrokes :wink:

Tom, I think programmers would call me a brute then… :joy:

Hey David,

I mean you have to work OSX's Graphical User Interface with Keyboard Maestro.

And this gets very interesting when you have to manage processes like printing.

You have to select a given message, manage any attachments, select print, watch the print process and detect when it finishes – repeat.

It's complicated, and you're talking many hours of work.

That doesn't mean it can't be done, but you're looking at a pretty big project.


Hey JM,

Good catch.

I haven't tried it, but I looked through the code. It seems pretty competent.


I will look at this and see how I can use it. I thought I'd need another apple script to determine the right emails. But turns out you can make a smart folder. So that should make it easier.

not sure what it does with attachments. Any idea?
What about this one, is it easily adjustable to be used with Evernote?

Hey David,

That's the “smart” way to do it.   :)

Scripting that sort of thing is fairly easy:

set theDate to current date
set theDate to theDate - (365 * days)

tell application "Mail"
  set msgList to messages of inbox whose date sent > theDate
end tell

BUT. If you're working on a very large mailbox Mail will grind to a halt and take forever to return a result.

So. The better way is to use a smart mailbox.



Looks like it handles attachments fine, but I have NOT tested it.

Just open up the script and search for "attach" and you will find a number of hits.

Here's the main handler for attachments:

on attachment_process(thisMessage, n)
  tell application "Mail"
    set AppleScript's text item delimiters to ""
    set ExportFolder to ((path to desktop folder) & "Temp Export From Mail:") as string
    set SaveLoc to my f_exists(ExportFolder)
    set theAttachments to thisMessage's mail attachments
    set attCount to 0
    repeat with theAttachment in theAttachments
      set theFileName to ExportFolder & theAttachment's name
        save theAttachment in file theFileName
      end try
      tell application "Evernote"
        tell n to append attachment file theFileName
      end tell
      set trash_Folder to path to trash folder from user domain
      do shell script "mv " & quoted form of POSIX path of theFileName & space & quoted form of POSIX path of trash_Folder
    end repeat
    set success to my trashfolder(SaveLoc)
  end tell
end attachment_process

I think not using a smart folder (which gave me wrong results, included things from June 2015 - possibly because the thread spreads a few months? not sure why) maybe not be the best way to go about it, but your script looks promising.

Since I am planning to run this every 24 hours (on a headless system during the night), it shouldn't be too bad?
I have exported all mail up until yesterday 1 year ago in one big swoop with a trial version of Mail Archiver X, so the mailbox isn't too massive.

How do I connect both scripts in KM or where do I add these lines in the script provided?