Hazel trash folder if it does NOT contain media

Hi all,

I’m struggling to make a certain Hazel rule. I currently have two rules:

  1. If kind is folder, run on folder contents.
  2. If subfolder depth is 1, and type is media, move file to enclosing folder.

From here, once the media file has been removed, I want to trash the folder. The folder won’t necessarily be empty, just no media files in it. I’m not sure if I can tell it to check the folder for it’s contents, make sure it has no media in it, and then trash it.

Can anyone help?

TIA, Lance

A quick and dirty way to do it might be after the folder has been there for X minutes, delete it, where X minutes is enough time for the media flies to be moved.

I’d just run a shell script on the sub-folder and then delete it.

Something like this:

#!/bin/zsh -f

zmodload zsh/datetime

TIME=`strftime "%Y-%m-%d--%H.%M.%S" "$EPOCHSECONDS"`



cd "$DIR"

mv -vn "$SUBFOLDER"/*.jpg "$DIR/"

mv -vn "$SUBFOLDER"/*.png "$DIR/"

mv -vn "$SUBFOLDER"/*.mov "$DIR/"

	# copy and paste these lines for whatever kinds of files you want to look for
mv -vn "$SUBFOLDER"/*.gif "$DIR/"

	# this will move the sub-folder to the trash, with a unique timestamp, so you won't
	# risk conflicting names preventing you from trashing the folder

exit 0

Obviously you’ll want to test that before you use it on any irreplaceable files, but since it’s just moving to the trash, not deleting, the sub-folder, it should be relatively safe.