Sorting files by projects

Hello fellow Automators! My projects have common structure so i am looking for opportunity to sort files to proper project folders. Plan looks like this: using KM “Prompt with list from text” append comment to file with project subfolder number, and then lest Hazel do the rest. The problem is i do not understand how to make rules for Hazel to sort files for present and then for future projects (137-138-139 and so on) with same subfolder structure.

I’ve read Hazel manual, Patterns in actions, but still have no glue haw to solve this. Please point me where to dig. Thank you!

You’ll want to use Hazel’s “matches” rule criteria, so that you can tokenize the number you wish to use as the folder name to sort the file into. Tokenizing the number will allow you to later use it to dynamically name folders to sort these files into.

In the field after the “matches” criteria, choose “Custom Text”:

Then create a token pattern similar to the following:

Then for the rule action, use the “Sort into subfolders”, and use the tokenized folder name (number) dynamically generated by the "matches rule above to generate the num red folder name.

Hazel will create the folder if one doesn’t already exist.

2 Likes

Thank you, George! Will try today

Hello George! Sorting from desktop works well, thank you!

Have question about folder structure. I can make Hazel place sorted files in destination folder but only in one-level structure, where folders like this: Projects [130 130-1 130-2 130-3 131 131-1 131-2 etc]. This works just perfect, and as you mentioned Hazel creates subfolder if there was no existiong with proper number.

And is it possible to sort files inside nested folders, like
Projects:
130
— 130-1
— 130-2
— 130-3
131
— 131-1
— 131-2
etc

?

I am assuming you are manually renaming these subfolders? You are not looking for Hazel to rename them, and then sort?

You want to manually rename, for example, a folder to “130-1”, and then have Hazel sort it as follows:

Destination_folder → 130 → 130-1

If so, just change the “name matches” rule to:

This will look for folders that match the NNN-N naming pattern, tokenize the main folder number (NNN) so it can be used later in the rule actions, and then use that main folder number as the main folder number to sort into.

Using the “matches” rule criteria, and then tokenizing the match, allows you to extract segments of data to be used later in the rule actions.

This setup is assuming the folders are named matching the pattern NNN-N. There may be ways to automate this process as well, and not have to do it manually via Keyboard Maestro.

Hazel has number incrementation rule actions. So if the folder meets a certain criteria, you can have it increment the numbers in the folder name to match a pattern.

2 Likes

Yes George, they all will be created on project start

@george_c what is the other possible way to automate the precess without KM? Still did not resolve this project — semi-automatic sorting different files from desktop to subfolders with proper numbers. -1 means legal, -2 marketing, -3 finance etc.

Hazel has file name incrementation actions, so you could set things up to just drop a new folder in the container folder, and have Hazel analyze the existing folder names, and rename the newly-added folder by incrementing the numbers in the name of the existing folder with the highest numbering.

So Hazel would see the folders 130-1, 130-2, 130-3, and then when you add a new folder, the rule criteria can be set up to match to that pattern (in this case, “does not match NNN-N”).

You would construct your match to use digits, match the “130-1” and similar folders, determine which one has the highest count (I would match the “ - N” string, and then increment that “N”.

In this example, 130-3 would match as the string and the highest count, and the folder would be renamed as “130 - 3[+1]” (the [+1] being the numerical incrementation, not the literal filename).

don’t understand yet, but will test it in my experiments. Thank you, George!