Page 1 of 1

Custom Matching 101: Sort Files into Alphabetical Folders

PostPosted: Tue Sep 04, 2012 4:26 pm
by a_freyer
There have been a few folks asking how to sort files into alphabetical folders, so I thought I would post a step by step tutorial. e.g. Sort "Time Machine.pdf" into the "T" folder.

This is how the rule will look when we are done:

Code: Select all
if (all) of the following conditions are met for (the file or folder being matched)
    Name matches (FIRST LETTER •)(REST OF TITLE •)

Do the following to the matched file or folder
    Move to /Directory Containing All Alphanumerical Folders/
    Sort into subfolder with pattern (FIRST LETTER •)



Think of a token as a piece of a file name. You can make the piece a letter, a number, a word, a digit, a symbol or any combination thereof. In Hazel there are two kinds of tokens: (1) generic and (2) custom. A generic token is what you see in the default matching floating window - letter, digit, word, etc. - and they can be used to build a file name pattern matching template. However, a GENERIC TOKEN CANNOT be used in the action section of your rules. They are generic - they only are used to match a file. On the other hand, a CUSTOM TOKEN CAN be used in the action section of your rules. This is because a custom token has a name.

In this forum, myself and others will generally note a custom token with a • mark (OPT+8 on a mac).

Step 1: Create a Rule Using Two Custom Matching Tokens


As shown above, we first create a rule and add a name matches condition. Next, we are going to add two custom tokens.

Click within the input box after Name Matches and a floating window appears. Drag custom (•) from the bottom right hand corner into that box. Another floating window appears. From this floating window we add the title and the elements of the custom token. For our demo, we have two. When the first one is created, drag a second custom token to the right of the first.

Custom Token 1:
Name - First Letter
Elements - Single Letter (a)

Custom Token 2:
Name - Rest of Word Letter
Elements - Anything (...)


Step 2: Add Sort into Subfolder Condition after Moving to Parent Directory (Optional)


Hazel executes rule actions sequentially. So, in our example above we can move the file into a parent directory and still execute subsequent actions even though the file no longer exists in the monitor directory.

Now, add a sort into subfolder rule and you will see that both custom tokens appear in your list of possible tokens. Without adding any slashes, drag (First Letter •) into the input dialog.

Hazel will create folders as necessary.

And we're done!

Re: Custom Matching 101: Sort Files into Alphabetical Folder

PostPosted: Mon Jan 07, 2013 12:01 am
by scottfwalter
Based on the example you provided I believe Customer Token 1 should be "Single Letter" instead of "Single Digit". If you use "Single Digit" Hazel will never match "Time Machine.pdf".

Thanks for creating this tip, this technique is very useful.

Re: Custom Matching 101: Sort Files into Alphabetical Folder

PostPosted: Mon Jan 07, 2013 12:08 am
by a_freyer
Very correct! Thanks for pointing that out!

Re: Custom Matching 101: Sort Files into Alphabetical Folder

PostPosted: Fri Jul 24, 2015 10:02 am
by deacone
Whew...Great post. Took me awhile but thanks for spelling it out so simple.