Add date to file name

This is an ask (maybe a bit of a contest :wink:) for some design chops.

Setup:

I have a lot of old emails that I need to bring more order to within various folders.

As a first step I’m going to order them by date. The metadata for date sorting is gone so I’m going to open them one by one (ugh) and find when the email was written and add that date to the beginning of the file name then sort by name.

Typing the date is more (ugh) so I whipped up a quick date slug generator with a Keyboard Maestro palette. What I made with my limited knowledge of programming works BUT, I’d like to see if anyone can do it more elegantly and of course more heads (in my case almost any head) is better than one.

Here’s my simple solution.

The UI is this:
SCR-20241221-ojcp

And the macros are this:
This puts the year at the beginning of the file name.


This adds the month by putting the already selected file name from step 1 into edit mode and pushing the cursor around:

And this just types the day to the already positioned cursor:

At this point it takes a double click to open the file to find the date. A click to close the file and three clicks to insert the date.

What better solutions do you have for a limited knowledge of programming?

I've stayed up too late already so I can't examine this in detail right now but I wondered about this:

If the emails have intact headers you could perhaps use Read a File and then get the date using regex matching. Perhaps. It could take a while to work out… Good practice though! :wink:

My instinct would be to copy the filename, transform it as needed and then paste the result back in.

I'm sorry I can't study this more at the moment, but I'm sure somebody else will provide a proper analysis and ideas soon!

2 Likes

Roughly how many? If it's more than 20, the method you are describing sounds like a total nightmare to me (and I'm someone who likes repetitive tasks :rofl:).

Like @kevinb is saying, the first thing I would do is try any method to automate getting the date from each file. If that can't be done maybe a method to copy and format the date using OCR rather than having to do it by eye each time.

And if you have the file selected in the Finder you can combine its name with the date and rename all without using clipboards or arrow keys using Keyboard Maestro's rename file Action:

2 Likes

A few hundred emails and yes it would be a grind to do that manually. As parsing the email with a script seemed out of reach I thought within the tools in reach. Upon looking for automation I found: Rename .eml File With Email's Date and Sender With KM and Extract Date and Time from Apple Mail.

These will be nice to chew on over the Holidays and are just the right amount of stretch for me to learn a bit from.

Thanks for the nudge your objection to repetition provided. Hearing it from another was just what I needed.

Having community here is really all I want for Christmas. Thank you all! :snowflake: :christmas_tree: :partying_face: :clinking_glasses: :tada: :snowflake:

1 Like

The spirit behind offering something to not leave a gap in the communication is generous. And generosity is an expression of caring that seems in short supply these days.

Thank you for the gift! Enjoy the Holidays!

:bowing_man:

2 Likes