How to get Hazel to sort pictures to year/month/ folder structure?

I am stuck with this automation question. I huge amount of digital pictures from year 1997 and would like to merge everything to two level folder structure like

Dropzone/1997/01/1997-01-02_12.13.15.jpg
Dropzone/1997/01/1997-01-02_12.13.20.jpg
Dropzone/1997/02/…
Dropzone/1997/04/…
Dropzone/1997/…
Dropzone/1998/01
Dropzone/1998/02
Dropzone/ …

You get the idea…

Dropzone is the root folder of this structure.

Idea is to drop all the images I can find to Dropzone -root folder and let the Hazel to move, sort and throw duplictes away correctly.

When dropping file to Dropzone:

  1. Hazel renames image-files based on EXIF -information.
  2. Hazel sors them to subfolders based on their modification date throwing duplicates away.

Everything works fine on the single folder level. I can sort my pictures to folders using year_month naming like:
1997_01/
1997_02/

Problem with that is that every sub folder are on the same level creating long list of folders since 1997. I would like to add one more folder level; year so it would be easier to navigate and use.

I tried to create another Hazel rule that sorts created folders based on the year on their name. That also works fine till I add new pictures to dropzone. Adding new pictures will create another folder 1997_01 and now the following folder sorter role can not merge two folders correctly.

Is there any way to make Hazel to sort my images directly to this Year/Month/ structure and cope with duplicates as neatly as it does on the single folder level?

Have you tried using the “sort into subfolder” action within Hazel? Macsparky has an example of non-image files, but that might give you enough ideas to get going.

If you need more help, let me know. I have a (differently-named) drop folder that renames and then subfolder-sorts my images. It’s quite nice!

Hi,
and many thank’s for your good tips, they were very useful when solving this puzzle.

Not directly related to my original question but for the background of the solution:
Importing huge amount of images from multiple sources I bumped to interesting problem.
Depending how and from where I copied the originals, copy between different os-platforms rewrites ans so destroys original creation date. For some images I had to use Imagemagick’s identify program to fish for the original creation date from the exif-data.

Identify is command line tool that’s part of Imagemagick package. Using:

identify -verbose IMG_7067.JPG | grep DateTimeOriginal

will reveal original creation date in most of the cases. Like here it says:

exif:DateTimeOriginal: 2003:12:28 15:31:41

Then I can use another command line command touch to fix modification date like this:

touch -mt 200312281531.41 IMG_7067.JPG

I had to write some shell scripts to fix some batches of images from my ancient windows (yack) machines using above tools.

Here are the rules and process I used to make it work. Trick was to do it in two phases.

To start the process I drop all un-sorted images with correct modification date information to drop zone -folder that has the following rules:

Then First Hazel rule renames files based on their modification date yyyy-mm-dd_hh.mm.ss.xxx. IF subfolder Depth is 0.

1stRule

Here’s the rename-pattern:
5

In the same rule images will then be sorted initially to the year folder of their creation. Subfolder Depth 0 is critical to prevent recursion happening. This was key to understand how to get this thing working.
2

Hazel did not recognize all my images to be image so I had to add those .jpg and png extensions to the selection which made everything to work correctly.

On the second Hazel rule ‘If the kind is folder, run rules on folder content’ we make third rule work.
3

Now as images are neatly waiting in the root of the year folder, the third rule will sort them further to monthly folders:

6

Once again the Subfolder Depth selectors keeps everything working correctly preventing recurision that Initially was causing issues to me.

Now with this set up and runnign I can keep dropping randomly named original images from different sources and they will automagically find their way to right destination and there is no problem with duplicates as Hazel will take care of that.

Finally I can have them all in one structure which I belive will withstand time very well for comming years.

Thanks for your help.

3 Likes

Hi all, hope that you can offer some advice, on the following - I’m currently using Mac OS Big Sur - Hazel 5.0.6 - and have been building on the structure above - but have come across a number of errors, I was wondering if anyone in the community could offer some advice -

in the current build of Hazel - there doesn’t seem to be the
" - If Any of the following conditions are met for the current file or folder " in the current build.

When hazel is run, it correctly creates the year folder but fails to make the monthly folder structure like the above example - if return it will then re-run the rules processing the file yet again .

hope that someone can help this is a great idea thanks for all your hard work.

best regards

1 Like

Hi Kalle

I am on Mac OS Big Sur - Hazel 5.0.6 - It works fine. I assume you are saying you can’t find the if any command?

You just need to hold down the ⌥ (option key) and the [ + ] will turn to [ … ] you can then choose the if any logic.

hope this helps.

One problem I have: the date might be stored in XMP sidecar files. Or is Hazel able to work with them?

I’m in 2024 and it’s absolutely magic!
God bless you man !
It works fine I had been spending hours to make it and it’s finally here!
Thanks again!