Rename File does not work

Hi all! I am quite new with Keyboard Maestro and do my first small steps. Currently I am struggling with a simple renaming of one and/or multiple files. Quite simple, the file name shall be kept, and as a prefix I want to add current date.

In the (fantastic) forum I found this example: Rename File. It's pretty much what I was looking for, so I adopted this for my purposes.

My understanding of this macro is, that it should actually also work for multiple files. But unfortunately, it doesn't work at all.

I'm almost embarrassed to ask, but where's the mistake?

Hi @knrk,

No need to be embarrassed; this is a fairly new problem you've run into. The issue here is that your for each collection is set to the Finder's selection, but you're using the new dragged file trigger to run the macro. Just set the LocalFile variable to the %TriggerValue% token first and remove the enclosing For Each loop and it should work fine (macros triggered by the dragged file trigger execute a separate instance of the macro for each file dragged onto it, which means For Each isn't needed, and it won't properly list the changed file names in a local variable). An example:

Example Macro.kmmacros (2.0 KB)
02 PM

1 Like

Thanks gglick, for taking away the doubts from me, for the explanation and the solution - it perfectly works fine now.


1 Like

I thought you always needed to add the parent path to the output path?

No problem, Klaus. Glad to hear it’s working now. Feel free to come back and post again if you find yourself perplexed again.

Nope, the parent path is only required if you want to move the file to a different folder. If all you want to do is rename, the name alone will suffice. From the KM wiki:

If you wish to rename a file, specify the new name as the destination[…]by itself, or with a full path that is in the same folder as the source location.


If the new name is the destination then what is all the date prefacing for? Why not have the Move to be: %Variable%LocalFileName%

Re-reading this thread, the point of the rename was to prepend the current date to the existing file name. If the file was only moved to LocalFileName, there essentially wouldn't be any change made to the file name at all.