I often send to myself (don’t ask but it’s from a mainframe and no reason to snigger on that either) data sets which get saved to disk on my Mac as files whose names are of the form
PACKER.HMLR1019.x.y
And I’d like Hazel to automatically rename them to
x.y
Actually the parts before the second dot aren’t constant. The folders within Documents aren’t constant, either. Indeed the HMLR1019 is a subfolder of ~/Documents/Customers/HMLR - most of the time.
Can Hazel do this? If so it would save a manual step in my workflow that is tedious - particularly if there are multiple such files appearing at once (which there often are).
Having had Hazel for a few years this is actually my first practical use case. Shame on me.
Use Hazel’s pattern matching and custom text match items to match the three file name parts separated by periods. The examples are identically defined alphanumeric parts, so I’ve applied explicit alphanumeric matches.
The rule drops the first and second custom parts and simply outputs the third and the extension.
This rule will run after the first rule due to the sequencing of the rules.
RULE #3: Go into Sub Folders
This rule matches all folders and runs the group of rules against them. This in effect gives the rule set a recursive folder action where it applies the rules to all sub-folders of the Customers directory.
I gave it some quick testing and it seemed to work as I expected, but if you examine the rules, backup your data and then give it a test, hopefully it’ll do what you are after.
If you have a new question, it is best to post it as a new topic. This makes topics easier to search for and also keeps the original topic on topic.
This discussion thread includes discussion of breaking a file name into multiple parts and using just a subset of those parts. You could apply this to your scenario by making "# " one of the parts and then dropping it.
Alternatively, you can use the “Rename” rule and click on the little arrow to the right of “name”, then select the “replace text” option and replace # with nothing.
I’m not at my Mac and don’t write Hazel rules regularly enough to recall, but does the replace text replace all instances, or accept regex to specify a pattern?
The removal technically should only occur once and only at the start of the name.