Custom Matching 101: Sort Files into Alphabetical Folders

From your noodle to other noodles. Talk about ways to get the most from Hazel. Even exchange recipes for the cool rules you've thought up. DO NOT POST YOUR QUESTIONS HERE.

Moderators: Mr_Noodle, Moderators

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!
Last edited by a_freyer on Mon Jan 07, 2013 12:09 am, edited 1 time in total.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

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.
scottfwalter
 
Posts: 47
Joined: Thu Jan 03, 2013 11:10 am

Very correct! Thanks for pointing that out!
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Whew...Great post. Took me awhile but thanks for spelling it out so simple.
deacone
 
Posts: 1
Joined: Fri Jul 24, 2015 8:58 am


Return to Tips & Tricks - DO NOT POST QUESTIONS