Rename Files in a Folder Based on a List in Clipboard

Does anyone know if it's possible to create a macro that renames files in a folder based on a list in clipboard?
The files are numbered (or at least they all contain a number in a sequence) and each should be renamed from
number1.jpg
to
first-new-filename-from-clipboard.jpg

etc.

Any suggestions? Im new to KM and slowly trying to build macros. So I just want to know if I'm heading down a dead end or not.

Hey Keith,

Sure you can, but personally I think this is a very bad idea – there are too many things that can go wrong.

I think it's better to actually map your replacements directly, so there can be no mistakes with sorting or interruption of the Clipboard – etcetera.

Personally I'd use BBEdit, because it's very scriptable.

I recommend BBEdit because…
  • Although BBEdit is a commercial product, the trial version reverts to a
    still very powerful and free (BBEdit-Lite) version after 30 days.
  • It is very Mac-like.
  • It has excellent support for RegEx.
  • It is very AppleScriptable.
  • It has a two versatile command line tools.
  • It has been in continuous development for over 25 years.

A decent alternative is CotEditor, but it's not nearly as powerful as even the free version of BBEdit.

Another alternative would be Apple Numbers.

So your document would have a tab-delimited table of name-value – rename-value:

number1.jpg				first-new-filename-from-clipboard.jpg

With enough tab separation to create a neatly ordered table.

You then use an Execute an AppleScript action to get the values into Keyboard Maestro and process from there.

Let me know which way you want to go, and I'll provide some more guidance.

-Chris

1 Like

Interestingly I just looked at BBedit last week.
I use VScode and Sublime and they seem fine for almost everything I'm doing so far.
Happy to go with either method but intrigued by the first one, which I guess is some kind of shell script?

I like VSC and have mixed feelings about Sublime – unfortunately neither of them is AppleScriptable.

I use VSC for writing JavaScript and a few other things, but my daily driver is BBEdit and has been for about 30 years now.

  • The appended macro makes use of a rename map table in a BBEdit document named “File Rename Map.txt”.
    • The BBEdit document MUST be named this way, although the user can change this if desired.
  • The Target-Directory is the FRONT FINDER WINDOW.

Note:

  • I have not taken the time to build in error-checking for a missing rename table window and various other things.
  • If I was building this macro for myself I'd have done all the heavy lifting in AppleScript.

Download: Rename Files from Text Table in BBEdit v1.00.kmmacros (7.5 KB)

Macro-Image

Keyboard Maestro Export


Operation Instructions:

  1. Create your rename table.
  2. Make sure it is named “File Rename Map.txt”.
  3. Make sure the table is open in BBEdit.
  4. Make sure the target directory window is open in the Finder and FRONTMOST.
  5. Run the macro.

Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.

System Information
  • macOS 10.14.6
  • Keyboard Maestro v10.2

1 Like