Thanks for hopping aboard. (And my apologies for not responding to Mr Noodle's invitation at the time).
What can I say? I feel your pain ... I've been on a merry dance with this one, exploring various scripting approaches. (Even asked ChatGPT b

). I'm very much a noob, you see. I have zero IT training. But I enjoy tinkering with automation, including scripting. Crazy really, but I like it. Well anyway ...
I ended up more or less getting there with a bash script. It runs in two parts. The first part (in theory at least) forcibly removes the .DS_Store files, allowing the second command to then nuke the folders (recursively of course). The two commands are:
- Code: Select all
find /path/to/the/folder -type f -path '*/\.*' -exec rm -f "{}" + 2>/dev/null
and
- Code: Select all
find . -type d -empty -exec rmdir -p "{}" + 2>/dev/null
.
(Probably should add that I've found reason subsequently to wonder whether I need "rmdir -p" in that second one, or whether "rm -rf" would be as good or better for the folders as well as the files. Or even combine the two into one with "rm -rf"?).
I say "in theory" because I actually don't know for sure what happens, and almost no one else I've consulted (human or machine) seems to either. I get the impression this nested-empty-folders thing is one of the untapped mystery frontiers of coding (or something). That and the mystery of .DS_Store, which few seem to have a grip on. e.g. - do we even know for sure that those blighters aren't like the zombie apocalypse? I get the impression Finder will recreate them on all manner of cues.
At any rate I tried more Hazel rules than I can count, and ended up deleting them all. After ruling out every condition and action my nooby brain could contemplate, there wasn't much left to keep. (And thanks, but yes I have picked up the stuff about subfolders in Hazel. It didn't help with this one, though). Broadly the .DS_Store files seem to remain the big imponderable. And I just drew a blank on how Hazel could manage it. The obvious disclaimer being that as a rank amateur in this field, my judgements don't warrant high trust.