Hi, I am trying to automate a process that may use Keyboard Maestro, or Automator (or both) depending on how it ends up. One thing I do know is that as part of the process I need to:
Look at a filename
Loop through an array of 'phrases' (100 or so)
If there's a match, rename with the prescribed change.
It's not just a case of renaming underscores as hyphens or dashes, as there are certain patterns, but thankfully the patterns are quite simple.
To give a snippet:
If I find 1-1-1-, I want to replace with 1.1.1-
1-4-1- changes to 1.4.1-
1-4-10 changes to 1.4.10-
Basically, some digits at the beginning of the file, which are hyphenated need to change to . but ONLY those first two hyphen instances.
I already have a lookup for the changes ready (although I am sure that this is possible with Regex but I will never get my head around that.
I am a web developer and I know exactly how I'd do this in JavaScript, but AppleScript is something that I just can't quite fathom.
If anyone is able to paste a snippet of AppleScript that could accept a filename passed in (if it were a step in Automator or KM) and show looping through an array of date based on the above, I would REALLY appreciate it.
[For info, currently I have the file rename (minus that specific request) set up as an Automator service, so I can highlight a batch of files and trigger it with a key combination (not via Keyboard Maestro, but in the macOS shortcuts). If this is something that would make more sense to do in KM, I am all ears as that would make syncing such things across my Macs better, anyway.]
This is PERFECT. Thank you so much, it works exactly as I want it to, and I'm much happier to have this in KM than in an Automator app. But what's more, having a complete working example that you have provided means that I am able to amend that and adapt that for further similar tweaks. I can learn from this one.
And also know I have JavaScript automation to learn about.