Macro to batch rename files working as intended despite throwing a lot of errors

This is my very first macro, it renames files (images in this case) sequentially based on the name of the folder they are in. I used it successfully for more than thirty thousand files but for every one of those files it threw an error about the "Move or Rename File" action, the error said that KM couldn't rename the file because it already existed but it didn't, no file had a name based on it's parent folder before. I thought the macro had failed but when I checked all the files had been renamed successfully.

Maybe the macro is running twice through all the files?
What am I doing wrong that is throwing all those errors despite working successfully?

Keyboard Maestro Export

I have three ideas that could help you.

  1. Errors, like the ones you see, also appear in the KM Error Log file. Sometimes you get more information in that file than you do in the pop-up error message. So check that out. I think the file is stored in ~/Library/Logs/Keyboard Maestro/Engine.log
  2. KM has a debugger. If you open the debugger and step through the macro one step at a time, there's a good chance you will see the cause of your problem. However I notice you are using instance variables instead of global variables, which makes debugging a little harder because in the KM editor you cannot see the values of Local Variables (and I presume instance variables too) in the editor. So for the purpose of debugging you might want to replace your instance variables by global variables. I usually use global variables, then once I've debugged my code, I convert my variables to local ones.
  3. It seems like you could create your own "log" by adding a statement before or after your "Move or Rename File" action that would be a "Set Variable to Text / Append to Variable" action. You would use a global variable in that action and you would be appending all three of your instance variables to it (preferably on three lines, with an empty line after all three to help make reading the variable easier at the end when the macro finishes.) No doubt you would see in that log when the file is being "moved twice."

Alternatively to idea #3 you could instead use the KM action called Log Action which could append the same data into the actual KM Engine log file.