Insert Date in file name

Hi all,

Newbie trying to figure out my way around. Hoping someone may be able to offer a suggestion.

Im looking to create a Macro which inserts the creation date at the beginning of the file name in this format. XXXX-XX-XX File Name (Year-Month-day file Name). Any help is greatly appreciated. Thanks!


What file name? How are you choosing the file you want to adjust?

Selecting in the Finder perhaps?

Thanks for the prompt reply. Yes, selecting a file or group of files in the finder. The File Name doesn’t need to be altered, just the insertion of the creation date before the existing name.

Start with:

the third example shows renaming the file. You just need to change how you rename it. Instead of Search and Replace, just use:

Set variable FileName to text "%ICUDateTime%yyyy-MM-dd% %Variable%FileName%"

Set Variable to Text.kmactions (405 B)

Hi Marc,

This can be done by adding a Get File Attribute action and the %ICUDateTimeFor% token to the file renaming macro I showed you before (new actions highlighted in yellow):

Rename Files with Creation Date.kmmacros (4.2 KB)
46 PM

The Get File Attribute action gets the file's creation date in unixtime, i.e. a long number like 153342876 that counts the number of seconds since the year 1970 began. Obviously this isn't very readable to humans on its own, so we have to use the %ICUDateTimeFor% token to format it into a yyyy-MM-dd date like 2018-01-28.

1 Like

Wow you know a lot! Guessing your not just a casual user lol. So helpful! I’m trying to learn this and all the jargon. Really appreciate the guidance! I’m curious, when I see ‘split path’ in the macros, what exactly is that? Just part of the total path?

Thanks Gabe!

Heh, you're quite welcome. Glad my post proved helpful. The Split Path action is a new addition to KM that makes it easy to save different parts of a file's path into separate variables. It's easier to see what it does if you enter a file path manually:

36 AM

If you want to learn about any action, select Help from the gear menu on that action, and it will take you directly to the help on the action, in this case, the Split Path action.

1 Like

Thank You!

Have you used KM to merge multiple pdf’s into a new document and then deleted the original documents? I ask because I am trying that with automator so I can setup a workflow macro. I can combine the pdf’s in automator to a new merged file but can’t see to delete the originals. Wondering if KM offers a better way to do this. Ever tried? Thoughts?

I haven't tried this before, but it doesn't seem too difficult. You'll need an Automator workflow like this:


And a macro like this that runs the workflow and then deletes the selected files:

14 PM

Here are the ones I made to help you get started:

Combine and Delete Selected (96.9 KB)

Gabe you are the man! I feel like I should send you something for all your help! Not sure how to do that though. Ideas? I had the same thing for a automator workflow as you put together. I tried adding the send finder items to trash and excluding the merged files but it didn’t work as it moved everything to the trash and figured KM might work better.

I happened upon a macro on the forum that seemed to be faster than the automator workflow I put together. Only issue is it didn’t delete original files. Would I be able to simply combine your macro and the one I found as one macro? Or, would it be smarter to keep them as two separate macros and run one and then run the other right after?

Here is the macro I Found on the forum that uses KM to combine pdfs but doesn’t delete original files. Merging PDF Documents

Curious of your opinion. Thanks Gabe!

Heh, you’re very welcome, Marc. No need to worry about sending me anything; answering questions like yours helps me learn a lot too.

If I understand the other macro correctly, you may be able to delete the original files just by adding a Trash File action that uses the same %Variable%Path% variable as the rest of the macro after the final Execute a Shell Script action. If that doesn’t work though, I would recommend just sticking with the Automator workflow and macro I posted above, since you definitely don’t need to run both macros to accomplish this.

Hey Gabe,

Any suggestions on how to clean up this Macro? I just want the confirm message to say "XYZ moved to Murano Maintenance" NOT the full Path as it does currently.Move to Murano Maintenance.kmmacros (2.6 KB)


Answered in your other post:

1 Like