Page 1 of 1

Finding destination folder most efficient way

PostPosted: Sun Nov 24, 2019 7:17 am
by Juhpe
Is it possible to create complex folder structure and copy paste that structure with a different name and Hazel would do the work to find a destination folder to file. For example.

I know how to set conditions, that file finds to Person A - Example folder 1 and 2, 3 and so on... But if I add Person B folder OR person C, D with same structure, it is too much work to copy paste conditions and then change the final destination folder to different person in all of the conditions.

Person A - Example folder 1
-Example folder 2

Person B -Example folder 1
-Example folder 2

I would want to find solution, that first Hazel finds out that the file belongs to Example folder 1, and after that it would sort it to Person A or B or Y based on condition who's file it is. Then if I make changes to conditions or add new person X folder, I don't have to do so much work. Maybe using script and variables or how to find solution to this?

Re: Finding destination folder most efficient way

PostPosted: Mon Nov 25, 2019 1:10 pm
by Mr_Noodle
Can you provide a concrete example here, with real file and folder names?

Re: Finding destination folder most efficient way

PostPosted: Tue Nov 26, 2019 5:40 am
by Juhpe
I have a file that contains information about Mark’s car.

It should go to folder Documents/Mark/vehicles/Car

Now i have it working like this. Contains mark —> move to mark folder.
Contains car—> move to vehicles/car.

This is working, but if I add Jenny, Monica and they have also car, hazel should figure out who’s folder it belongs. This should be last step, because if they all buy private jet, I dont want to add Jet to every person. If file contains jet —> who’s jet —> move file.

When i have many folders and many persons, adding conditions should be easy as putting condition to hazel only once, not to every person.

Contains car —> path= documents/xxx/vehicles/car
Contains jenny —> path = documents/jenny/vehicles/car

Is this clear enough? When i got many folders, i should change now Mark to Jenny in tens of folder conditions. It would be great if a could add jenny only once and after that it knows file is about jenny’s car or bike, or plane or shoes or whatever.

Re: Finding destination folder most efficient way

PostPosted: Tue Nov 26, 2019 1:25 pm
by Mr_Noodle
You can have Hazel monitor Documents. You didn't say where the files are coming from but I'll assume they are coming from outside of Documents.

You would have rules to then match those files when they come in at the top level and put it in the appropriate named folder.

You would then have a rule to go into subfolders (please check the manual for details).

Then you would have a rule match files one level down and file them into the appropriate vehicles folder.

It is imperative you specify what level the rules pertain to as noted above, otherwise you will end up with an infinite loop.

I highly recommend you do this on a test folder/files before doing it on the real thing as this can be a bit tricky.

Re: Finding destination folder most efficient way

PostPosted: Fri Nov 29, 2019 3:01 am
by Juhpe
Thanks for your tips, I think I have a vision how to do this, but I have to do some testing to see if it works.

Re: Finding destination folder most efficient way

PostPosted: Fri Nov 29, 2019 6:42 am
by Trickyt57

I think it going to be easy to achieve the kind of "coat-hanger" structure you want by creating the required folders automatically based on the contents of each document.

For this example, I am going to assume you put the file into the folder called "test", and you will put all files which need processing and moving into the "test" folder. You want the folder structure which will automatically be created to reflect the owners name (level 1), and type of vehicle (level 2). You want the level 1 and level 2 directories to be automatically created and the file moved to the relevant level 2 directory.

You need to use the functions "contents==>contain match" and the "Sort into sub-folder" functions.

So for example if the text of the document contains the following two sets of words "Name of client: John" and "Type of Vehicle: Car", then you first create a token called "client_name" as per the picture below:


Next you will create another Token called "Vehicle_Type", as per the picture below:


Lastly, you need to use two "Sort into subfolder" actions as per the picture below.


As far as I can tell, there is no risk of a looping structure provided you do not have any command like "Run rules on folder contents". I tested it and it works.

My document that I initially put in the folder "test" contained the following text somewhere inside the document:

"Name of client: John"
and "Type of Vehicle: Car"

After running the above rule that document is now to be found in the folder:

I hope the above helps.

Re: Finding destination folder most efficient way

PostPosted: Fri Nov 29, 2019 9:55 am
by Juhpe
Thank you for help.

I got this working. Maybe this could be done different way, but this is what I hoped for, and now it is quite easy to "teach" hazel to find different kind of documents and to whom that document belongs. Point is to automatically sort papers and documents and then forget them. If mail brings any kind of document, I just have to scan it with my phone and basically then throw that document to trash can. Hazel does all the sorting from icloud scan folder.

This is how I did this.

Presorting phase

Monitored folder = DROP FILE HERE or iCloud phone scan -folder
Rule example = if content contains word car --> move to (Presort/Vehicles/Car)

Sorting to right person I used sync feature. (Example file from user guide with small changes)

Syncing phase
Monitored folder = Presort -folder
Rule example = Example from user guide + if content contains Mark --> sync to Mark folder

after that files are removed from Presort folder.

I got this working with small example files, now I just have to build complex rules to use it with bigger picture. Amazing software, thanks.

Re: Finding destination folder most efficient way

PostPosted: Fri Nov 29, 2019 5:33 pm
by Juhpe
Ok, so the sync was not good, because it removed deletions if files were removed from monitored prefolder.

But find solution that replaced sync feature. I use now go to subfolder and after that move files and sort them into subfolder with source folder pattern. Now this works like it should! Nice!