How to macro-ify this unusual operation

I have a folder of files in the Finder, which all follow this naming pattern:

apple01
apple02
apple03
apple04
orange01
orange02
orange03
orange04
pear01
pear02
pear03
pear04

What I need to do is create a macro that grabs the first set (apple01-apple04) and zips them, to a file called “apple.zip”.

Then on the next repeat, the macro would grab the next set (orange01-04) and zip it and call it “orange.zip”

Then on and on – literally thousands of times.

I can’t wrap my brain around how this might be accomplished in KM. Any ideas?

Hey David,

For my own use I would probably do this with AppleScript or as one Shell Script.

But I'll mix it up a bit in Keyboard Maestro.

Make sure you test this on a COPY.

Basically what I'm doing is getting a list of file names and stripping numbers and suffixes off the end.

Then I get the unique names.

Then I use that list of unique names to create the archives.

--
Best Regards,
Chris


NOTE: YOU have to change the dirPath variable to your target folder. The tilde (~) is an abbreviation for your home folder.

Zip Named Files.kmmacros (4.0 KB)

1 Like

Wow.

That is pretty intense. I don’t have enough of a scripting background to fully understand what you did. Thanks so much for figuring it out. I’ll give it a whirl!