yet another 'run rules on folder contents' question...

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

edit: Short version:
I want 2 folders, /1 and /2, where all of their contents (mostly folders with sub-directories) get copied to a third folder, folder /3, where I will deal with the files there and delete them when I'm done. First 2 folders contents remains there as a backup. I want this third folder to show colored tags on every folder within it at the first subfolder depth inside it, one colored tag for stuff that came from folder /1, and another colored tag for stuff that came from folder /2, so I can tell them apart while browsing in folder /3.

For: folder3/contents/subcontents/files
only 'contents' will receive the colored tag.

The catch is that all 3 of these folders need to have a 'run rules on folder contents' within them, because of other rules I have. This is causing issues where every file at every depth level gets a colored tag.


Long version:

I have 3 folders, /1, /2, and /3.

Folders /1 and /2 both get populated with files from a server automatically, not using hazel. Everything that gets put into folders /1 and /2, gets copied to folder /3 using hazel. Here's how I've been doing that:

If all of the following conditions are met:
    Date added is after specific date: 12/16/2022, 4:50 PM
Do the following to the matched file or folder:
    Copy to folder: 3 (options: copy the folder structure)
    Run rules on folder contents
^ this is set on both folders /1 and /2. Even tho I have 'copy the folder structure' set, 'run rules on folder contents' appears to be necessary, because these files inside of /1 and /2 are downloaded from the server in pieces. If I don't use 'run rules on folder contents', hazel will copy the folders the second they get added, and then when the folders inside /1 and /2 get more files, hazel will ignore them.

Folder 3 has the following rules:

if all of the following conditions are met:
    any file
Do the following to the matched file or folder:
    Run shell script: removesync.sh
(this shell script is just to remove files with a specific extention, trash generated by a combination of the program I use to sync files from my server + hazel)
Code: Select all
#!/bin/bash
find /Volumes/harddrive/3 -name '.syncthing*' -exec rm -rf {} +

If all of the following conditions are met:
    Kind is Folder
Do the following to the matched file or folder:
    Run rules on folder contents
^ I'm only putting this here to explain why I have 'run rules on folder contents' on /3.

The whole point of this setup is that I use folder /3 to see what new additions have been added to /1 and /2. Once I deal with those files in /3, I delete them, while /1 and /2 remain as backups of everything that's been downloaded.

This all works fine, but I'm trying to upgrade these rules to add a colored tag only to files/folders with subfolder depth 0 inside /3. This is so I can see by looking at folder /3, whether a file/folder came from /1 or /2. I don't care if the tags are added inside of /1 and /2, or if they get added when they reach /3. For cleanliness I suppose I'd prefer if it happens at folder /3. Looking at folder /3, I'd like to see files/folders that came from /1 to have a red tag, and files/folders that came from /2 to have a blue tag.

Here's what I've tried:
    1.) What If I set my rules on folders /1 and /2 to add a color tag while it copies to /3. On folders 1 and 2's rules, I add the option to 'set color label' right between 'copy' and 'run rules on folder contents'. This works ok, but because of my 'run rules on folder contents', it adds a colored tag to everything at every subfolder depth, and copies them to /3.

    2.) What if I made a separate rule on /1 and /2 that adds a color tag to any file. On folders 1 and 2, I add a separate rule, take 'any file' and 'set color label'. This will set color labels on the correct folders (subfolder depth 0, everything at the very first level inside /1 and /2), but nothing will copy to /3 for some reason.

    3.) What if I set my rules on folders /1 and /2 to add a color tag while it copies to /3, just as I did in example 1, but this time I make a rule on /3 to delete tags on anything greater than subfolder depth 0. On folders 1 and 2's rules, I add the option to 'set color label' right between 'copy' and 'run rules on folder contents, just as I did in example 1. This time I go to /3, and set a new rule: if subfolder depth is greater than 0, remove tags: any existing tags. If I do this, the files will copy properly, but it does not delete any tags on folder /3.

    4.) What if I made a new rule on folder /3 that adds a color tag to anything with subfolder depth 0. I make a new rule on /3, any file, subfolder depth is 0, set color label. If I do this, no color labels get set.

I'm running out of ideas here! I think this 'run rules on folder contents' setting on each of my folders is making this difficult to solve. What can I do to accomplish this?

Another idea: Again, my 'run rules on folder contents' setting on /3 is just to remove those pesky .syncthing files. Basically the program I use to copy files from my server, syncthing, will create temporary .syncthing files. Once the files are fully copied, the .syncthing files delete themselves. Without using my removesync.sh script, I end up with these .syncthing files in every subfolder. They get deleted from /1 and /2 automatically by syncthing itself, but during the period where they exist, hazel copies them to /3. Maybe if there was a way to synchronize deletions, I could get rid of my script and therefor remove the 'run rules on folder contents' on /3. This might make it easier to accomplish what I want with color labels. I have looked into the 'synced folders' documentation, the example included is pretty far from what I'm trying to accomplish I think and it's pretty confusing. I don't think I really want to be syncing anyway, because I need to be able to delete files in /3, and have them remain in /1 and /2.

Thanks :)
gorilladunk
 
Posts: 6
Joined: Mon Dec 27, 2021 5:57 pm

You should not have "Copy files" and "Run rules on folder contents" in the same rule. If you are copying folder structure, then there is no need to copy the folders. Copy the files (not folders) and have the Run rules on folder contents happening on a rule that matches folders only.
Mr_Noodle
Site Admin
 
Posts: 11250
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

^ this is set on both folders /1 and /2. Even tho I have 'copy the folder structure' set, 'run rules on folder contents' appears to be necessary, because these files inside of /1 and /2 are downloaded from the server in pieces. If I don't use 'run rules on folder contents', hazel will copy the folders the second they get added, and then when the folders inside /1 and /2 get more files, hazel will ignore them.


Do you know an alternate solution then for this specific use-case?

For example, the server sends folder A with some files to folder /1

/1/A/file1
/1/A/file2

Hazel copies this over to folder /3, as expected. A few minutes later, the server then sends more files into folder A

/1/A/file1
/1/A/file2
/1/A/file3
/1/A/file4

Hazel ignores these updates, and all I get is

/3/A/file1
/3/A/file2

Files 3 and 4 are ignored. It seems like hazel doesn't recognize there have been additions once it initially copies.
gorilladunk
 
Posts: 6
Joined: Mon Dec 27, 2021 5:57 pm

Did you change the rules to copy files instead of folders? If so, can you post the updated rules?
Mr_Noodle
Site Admin
 
Posts: 11250
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

is that maybe a new feature or something? I'm not seeing it

Image

I don't see the option to "copy files" or "copy folders", only seeing "copy" in that dropdown. Did a quick search of the release notes since my version (5.0.6) but not seeing anything too obvious about adding a "copy files" or "copy folders" action.
gorilladunk
 
Posts: 6
Joined: Mon Dec 27, 2021 5:57 pm

When I mean copy files, I mean you change the conditions of the rule to only match files, and not folders.
Mr_Noodle
Site Admin
 
Posts: 11250
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Sorry, I think I'm just really just not understanding what you're saying, or maybe I'm bad at explaining myself. I'm guessing maybe what you mean is about the 'run rules on folder contents' rule. The docs show that the simplest use case for this is just "if kind is folder, run rules on folder contents". In my case that I posted above, I had 'run rules on folder contents' on a rule that was matching all files/folders. Maybe this is what you're telling me to correct? Well assuming that it was, I did manage to get this working using four rules on /1:

/1 rules
rule 1
if all of the following conditions are met
    subfolder depth is 0
do the following to the matched file or folder
    set color label = blue
    continue matching rules
rule 2
if all of the following conditions are met
    date added is after specific date, 12/16/2022 5:00 PM
do the following to the matched file or folder
    copy to folder /3
    continue matching rules
rule 3
if all of the following conditions are met
    kind is folder
do the following to the matched file or folder
    run rules on folder contents

rule 4
if all of the following conditions are met
    any file
do the following to the matched file or folder
    remove tags, any existing tags

this seems to do what I want. Folders copy from /1 to /3, if my server updates subfolders inside of /1, they successfully copy to /3, and the colored tags are applied where I want them, and then they disappear after they copy. Not sure if this is the direction you were sending me in, but either way, thanks :)
gorilladunk
 
Posts: 6
Joined: Mon Dec 27, 2021 5:57 pm

In rule #2, that will match anything, file or folder, that has the date added after that date. This is what I'm referring to. That rule will also match folders and copy them, which is a bad idea here, especially if you are having the copy action copy the folder structure as well.
Mr_Noodle
Site Admin
 
Posts: 11250
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support