I’m struggling to make a certain Hazel rule. I currently have two rules:
- If kind is folder, run on folder contents.
- 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?
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:
TIME=`strftime "%Y-%m-%d--%H.%M.%S" "$EPOCHSECONDS"`
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
mv -vn "$SUBFOLDER" "$HOME/.Trash/$SUBFOLDER:t.$TIME"
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.