doing this requires the appropriate combination of very simple rules. at minimum you need two parts: a rule that drills down the file hierarchy and a rule that moves image files. you can add an optional rule that cleans up empty subfolders.
the order of the rules is important! it has to be:
1. delete empty folders
2. traverse (non-empty) folders
3. move images
here are how those rules can look.
Delete Empty Folders
- Code: Select all
if
Kind is Folder
Sub-file/folder Count is 0
then
Move to Trash
Traverse Folders
- Code: Select all
if
Kind is Folder
then
Run rules on folder contents
if a folder is empty, the earlier rule will take precedence and trash it. if it has contents, they will be traversed.
Move Image Files (fixed location)
- Code: Select all
if
Kind is Image
then
Move to [top level]
Move Image Files (
push upwards)
- Code: Select all
if
Kind is Image
then
Move to enclosing folder
i prefer the second formulation of the Move rule. if you have a deeply nested folder structure, it takes multiple steps to
push the files all the way to the top (but Hazel will take care of that!). the benefit of using it is if you want to re-use this set of rules, you can just drag and drop them onto the new folder in Hazel. if you used a fixed location, then you'd have to edit the rule and manually specify the new destination.
if you have several folders you want to flatten at once, or want to create a place where you can drop a folder and it will auto-flatten, you can even get fancier by using subfolder depth! use the same set of rules on the folder
containing the ones to be flattened, changing the Move rule to the following.
Move Image Files (
push upwards)
- Code: Select all
if
Kind is Image
Subfolder depth is greater than 1
then
Move to enclosing folder