Change Filename Using a Wildcard


I have files being downloaded with different file names. There is only one file in the folder at any time.

The file names are like:


Where 443541 is a random number.

I'd like to change this to:


Hey @NorthernProject,

Here's a typical method for working with strings:

Change File Name Using a Regular Expression v1.00.kmmacros (6.9 KB)
Keyboard Maestro Export

There's your basic functionality.

Now – how do you propose to use it?

  • Do you want this macro to run on demand?
  • Do you want it to run automatically?

Please be more specific about your entire process.


I like it to run automatically. When the macro runs it looks in a directory with one file and chances that filename.

Okay, you need to look at:

Those should give you all the tools needed to complete your task.

Holler if you get hung up on something.

Thank you for you guidance @ccstone.

That took me to this solution:

Screenshot 2022-11-24 at 00.29.39

Best regards

"Set your wifi password to 2444666668888888. So when someone asks for it, tell them it's 12345678."

Some of that may be for troubleshooting as you wrote the macro, but:

  • You don't need to open the Finder selection to rename the files
  • If you are selecting multiple files your macro will break because you are appending to LocalFileList -- the "Move" action won't receive a correct file path, even if you move it inside the "For Each", and trying to name all the selected files 123.pdf will cause problems
  • If you are just renaming a file but leaving it in the same place, you don't need the file path in the "to" field of the action -- just use the new name
  • Using a "static" name like "123.pdf" could cause problems unless you always, always, move any previously renamed files before running the macro again

All you actually need to "rename a single selected file to 123.pdf without moving it" is:
Rename Selected File.kmmacros (1.2 KB)

But do have a think about what you'd eventually like to do. For example, you could "watch" your Downloads folder and any time a file whose name matched a pattern arrived you could automatically rename it -- no intervention from you. But that does mean you need a naming scheme that offers unique names (or both renames and moves the file) to prevent conflicts.