Editing A File Name With Hazel

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. :slight_smile:

A few clarifications that could affect how you might do this.

Are you saying that the files to be renamed by Hazel are always in sub folders of ~/Documents/Customers/?

  • Is y the file extension or is it part of the base file name and there is a further extension of some sort?

Good questions.

  1. It is always a subfolder of ~/Documents/Customers/ but for different customers the next one will obviously be varying.

  2. The y is the extension. Generally it is csv but sometimes I might want to rename .SCRIPTR to .csv. (That would be a stretch objective.)

Let’s create three rules in Hazel for the ~\Documents\Customer\ folder.

RULE #1: Base Rename

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.

RULE #2: Rename SCRIPTR Files

This rule simply renames *.SCRIPTR files to *.csv.

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.

In effect rules 1 and 2 are run against every older in the tree beneath Customers.

You can either build the rules yourself, or download and examine my test set.

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.

Hope that helps.

1 Like

Thanks for this. Getting it working taught me a lot about Hazel.

1 Like