Rename eml file with email's date and sender with KM

Good evening everyone.

Is there any way to rename an .eml mail file according to its date and sender (from the headers) with keyboard maestro?

Anyone did something similar or can give some hint?

Thank you.

Good evening to you, too @tsolignani!

It's easy to get the sender and date information if you have an email in eml format.

I've created an example macro for you that takes the contents of an eml file and performs the extraction using a couple of KM Search actions.

This is not a stand-alone macro insofar as you have to get the contents of an eml file into a KM variable; I do this in the example macro by explicitly setting the KM variable Local__EMLtext to the raw text of an email.

The macro then extracts the two fields into the KM variables Local__Date and Local__Sender. In the example these come out as:

= Local__Date =
Fri, 29 Jul 2022 13:16:04 +0100 (BST)

= Local__Sender =
OWL Messaging <>

Which might not be the format you're looking for but the information is there to rename the file.

I leave it up to you to produce a complete macro using mine as a starting point, but do ask further questions if you have them.

Here is the example macro for you:

Test - Get Date and Sender from eml.kmmacros (11 KB)

Click to see macro

1 Like

Hot on @tiffle's heels (but beaten again, dammit!), here's one where you can select an .eml file in the Finder then trigger via hotkey (change to suit):

Rename EML.kmmacros (4.0 KB)

Click for image

You can (and should!) error-proof this! For example, it assumes you are only going to run it on an elm file, and sets the file extension accordingly -- a better approach would be to extract then reapply the extension, at least then you'd retain app association if you selected the wrong file, or do a file extension test before proceeding.

As @tiffle points out, the information you've told us you want may not be what you actually want to see in the file name! But this should be enough to get you started.

And do note that "Sender" and "From" in an email's headers are not the same thing. We've both assumed you actually want the "From" header address -- if you do want "Sender" then change to suit.

1 Like