Watch a Folder and Rename Files Added to Current Month

Hi There,

I'm not sure if this is possible on something like KM or Hazel is better perhaps, however I'd like to try get this to work on KM.

I'd like to drop a file in a folder and it should automatically be renamed to the current month or sequentially renamed from the last folder saved there from month before. There will only be 12 files in the folder i.e. one for each month.

Automator is able to do this however it can only be named sequentially from a number.

Thanks in advance.

This is possible in Keyboard Maestro but probably simpler in Hazel.

That's too complicated for me to understand what you mean. :slightly_smiling_face: Is it that you want to rename existing files in the folder to the month when they were added?

For the first task here is a Keyboard Maestro macro. You will need to change the path to an actual folder on your Mac in the field I have highlighted (EDIT - thanks to @gglick for simplifying this Macro).

Breaking down how it works -

  • The Macro is triggered when a new file is added to the watched folder.
  • The Split Path Action gets that file's extension (if it has one)
  • The If All Conditions Met Action, renames the file to the current month and adds the file's extension back on the end of the name. (If the original file had no extension no extension is added to the end.)

EXAMPLE Rename Latest Item Added to Folder to Current Month v2.kmmacros (3.3 KB)

1 Like

I use the For Each action all the time—it may even be the single most useful action in KM, at least for my purposes—but there's no need to use it here. You can remove it entirely and just use the %TriggerValue% token to reference the file that's been newly added to the folder, or set it to the LOCAL__Path variable if you prefer.

While I'm at it, when renaming a file, there's no need to specify the directory if you're keeping the renamed file in the same directory, so you could also simplify the file action to:


Great. I learn something every day! (I hadn't realised that in this case %TriggerValue% would be the file and its attributes, like its name and path and extension). I've edited my first post to take account of this simplification.

One thing I found. I had to set the Gear on the Rename Action to not "Notify on Failure" otherwise I got an error saying the file already exists.

As an aside - it always throws me that this Action says "Move" rather than "Rename" or "Move and Rename".


1 Like

mmm dont seem to be able to get the above to work. Me pleb though lol

Did you change this to an actual folder on your Mac?

Or it could be the dreaded Mac OS permissions... check that Keyboard Maestro has Full Disk Access in Files and Folders in System Preferences/Security & Privacy/Privacy

Not that it helps you much, but it works for me. Every file I put into that folder gets renamed December. I'm going to have to disable that Macro :rofl:


awesome thank you so much for this...