Page 1 of 1

Running Rules based on other Rules to different files

PostPosted: Tue Apr 11, 2023 6:17 pm
by chpstx
Hi! I've just got Hazel and I've setup a bunch of rules. I want to accomplish a simple task that relies on Hazel applying a rule to one file then modifying another file. Based on the quick read of the forum and documentation, I don't see a way to do this.

Basically, I want Hazel to see if there are any .png files under 500KB within a folder AND created in the last minute. If matched, I need it to find the most recent .mkv file and apply a tag (or even rename).

I already have a rule that will move .mkv files to another folder so I know I need to use continue matching rules as well and move this rule first.

Any help would be great! I record using OBS and I use a streamdeck to trigger a screenshot whenever I make a mistake. But if I do multiple recordings, this can get messy. Separating the files to different folders based on type cleans it up but then I need to cross reference the names of the screenshot and recording to know if I need to edit the video or not. By having Hazel add a modify the video file (by tagging or renaming), the editor can quickly see if the video requires edits. Tagging is probably better since the .mkv file is still writing when the rule needs to run.

Re: Running Rules based on other Rules to different files

PostPosted: Wed Apr 12, 2023 9:11 am
by Mr_Noodle
Does the mkv file have the same name as the png file? Are they in the same folder? If so, you can do it as follows:

- Create a rule to match the mkv.
- Use a nested condition to match files in the same folder.
- Have that condition check if there's a file with the same name (use "matches") but with a png extension.

You'll probably need to tweak that but that's the basics.

Re: Running Rules based on other Rules to different files

PostPosted: Mon Apr 17, 2023 3:09 pm
by chpstx
Thank you!

Shortly after I posted, I figured it out by using nested conditions and giving it a condition of an image, within the 1 most recent files, and size under 500KB. This seems to work perfectly as intended. Nested conditions did exactly what I needed it to.

Funnily enough, I did a forum search for using the "matches" rule and came across your answer to my previous post. I think your suggestion will work for what my next question was: Moving a file if there is a file with a matching name but different extension. Remuxing .MKV files automatically go to the same folder as the original file. I made a rule to sort the remuxed MP4 to a different folder but since I only use the MP4s for editing and they are synced to dropbox, this caused a mismatch if I used the MP4 in a program before Hazel moved it over. Since I don't use the MKV for anything, I'll have it auto trash bin the file if there's a matching name instead of moving the MP4s out of the folder.

Re: Running Rules based on other Rules to different files

PostPosted: Mon Apr 17, 2023 4:06 pm
by chpstx
Mr_Noodle wrote:Does the mkv file have the same name as the png file? Are they in the same folder? If so, you can do it as follows:

- Create a rule to match the mkv.
- Use a nested condition to match files in the same folder.
- Have that condition check if there's a file with the same name (use "matches") but with a png extension.

You'll probably need to tweak that but that's the basics.


I'm struggling to get the "matches" condition to work. There is no way as far as I can tell to have the condition Matches not have any rules (so it only applies to exact matches). Adding any type of rule or pattern (123)(...) etc will make it match other files or no files. Is there a way for it to only match exact name matches?

Re: Running Rules based on other Rules to different files

PostPosted: Tue Apr 18, 2023 2:12 pm
by Mr_Noodle
Just type the text you want to match into the field. Or am I missing something?

Re: Running Rules based on other Rules to different files

PostPosted: Tue Apr 18, 2023 9:58 pm
by chpstx
Yes. The names of the files are usually a date as per OBS. I don't want it to match a specific format but an EXACT name. So if there's 2 files both named Cat3.png and Cat3.mov they would be affected. But also if there's a file called Promo Video 4.png and Promo Video 4.mov they also get affected.

Basically, I don't want it to match any specific format or rule, but I want it to only find files where the names match, regardless of the contents.

Re: Running Rules based on other Rules to different files

PostPosted: Tue Apr 18, 2023 10:03 pm
by chpstx
Here is the image of the folder that I'm trying to apply the rule to.
Image

As you can see, there are 2 files with the same name but different extensions. I'm trying to move the MKV files to a different folder ONLY if there is a file with exact same name. Doing any of the other "matches" rules will make it match to other files since they have the same format.

Re: Running Rules based on other Rules to different files

PostPosted: Wed Apr 19, 2023 9:05 am
by Mr_Noodle
I see. You don't want a hardcoded name, you want to match one name to another. You need to use a match pattern on the original name, with a custom attribute to grab the whole thing. You can then use that custom attribute when matching against the other name.

Re: Running Rules based on other Rules to different files

PostPosted: Wed Apr 19, 2023 4:50 pm
by chpstx
I'm confused. If I do a custom attribute, what would I put out of the options that would be different? I put a custom text attribute with the "anything(...)" attribute within but it still won't match anything.

How do I capture the name for matching?

EDIT: Nevermind I figured it out, thank you! I had the wrong extension in.

Re: Running Rules based on other Rules to different files

PostPosted: Wed Nov 08, 2023 11:31 am
by gedeyenite
Mr_Noodle wrote:I see. You don't want a hardcoded name, you want to match one name to another. You need to use a match pattern on the original name, with a custom attribute to grab the whole thing. You can then use that custom attribute when matching against the other name.


I understand the theory here, but I am having difficulty thinking through how to actually implement this solution. I have the same use case where I batch convert .docx files to .pdf then want to delete, or, sort to a different folder, the original .docx.

Re: Running Rules based on other Rules to different files

PostPosted: Wed Nov 08, 2023 11:48 am
by Mr_Noodle
Please provide specific details for your use case.

Re: Running Rules based on other Rules to different files

PostPosted: Thu Nov 09, 2023 6:13 pm
by gedeyenite
Mr_Noodle wrote:Please provide specific details for your use case.


Sure can.

I received a mix of file types from work, and they sort via Hazel into subfolders. One folder is Orders, which contains docx files. After I review a few of them, I use an Applescript to convert them into PDFs. This will leave me with a folder like this:
Image

I want Hazel to recognize that those two files are identical in name except for the extensions, move the docx to a different subfolder, or delete them. I don't want to delete the docx as part of the Applescript because the Applescript isn't 100% and sometimes misses a file or three, and I have to rerun it.

Thanks.

-gedeyenite

Re: Running Rules based on other Rules to different files

PostPosted: Fri Nov 10, 2023 10:11 am
by Mr_Noodle
Image isn't coming through but based on what you described, you do want to use a nested condition. Have something like:

Code: Select all
If (all) are met
   Extension is docx
   If (all) are met for (any file in the same folder)
       Extension is PDF
       Name matches (name)


The above will match a docx file if it has a PDF in the same folder with the same name. Play with that to get what you need but that should give you the basic gist.