Issue With Comparing Other Files In Folder

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

Moderator: Mr_Noodle

Greetings All.

I have been having great success with Hazel, however after reading many posts on this forum, I still cannot seem to get the following rule to work.

First my folder contains files that exist in pairs. The names are formatted as (DATE_TIME)-(UUID).

Here is an example - these names are copied from the actual Finder (hit Enter on a file and CMD+C the file name).
20190403_104452-CDCB9801-2613-418A-AC60-398FFDF4813A.txt
20190403_104452-CDCB9801-2613-418A-AC60-398FFDF4813A.eml

The rule I am trying to get to work is the following - almost a direct copy of various samples on this forum. It just does not seem to work.

Code: Select all
if (all) of the following conditions are met
    (name)           (matches)               (Date Field)-(UUID)
    (extension)      (is)                    txt
   
     if (all) of the following conditions are met for (any file or folder in the same folder)
         (name)           (matches)               (Date Field)-(UUID)
         (extension)      (is)                    eml

Now the first 2 lines match - so my (Date Field) and my (UUID) fields work fine.

The second (if) works if I am trying to match the (extension) only. So it picks up that there is an eml file in the same folder.

However the minute I add the (name) condition the check fails, hence the second (if) fails.

I have tried variations of this, using a nested condition checking the parent folder then files in the parent folder as others have suggested on these forums and they still fail.

Any suggestions/help are most appreciated.
D
fly.ing.fox
 
Posts: 13
Joined: Sat Apr 20, 2019 5:09 pm

That looks correct to me. I can't replicate the problem here. In the preview, for the failed condition, click the red x button. Does everything look ok there?
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Oh, and is "Date Field" a date or text custom attribute? If a date, there may be a subtle issue so you might want to try using a text attribute, unless you need to do some date manipulation later.
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

First to answer the question - yes I am using Custom Dates and I need to do so because I am doing calculations on those dates in AppleScript. Of course I could possibly just pass the text version of the date and do the Class creation in the Script.

In the intervening days from posting and awaiting moderation I discovered a "quirk" in Hazel which was the cause of my error.

Since I was reusing attributes to capture information, I was just copying the attributes in the rules instead of creating them from scratch again.

Well it seems copying/pasting an attribute sometimes OR selecting it in the attribute definition box wipes any custom definitions inside that attribute.

Why was I copying and not recreating? Because I want them to have the same name of course. Recreating adds a 1 to the end of the name if it is the same as a previous one.

So now that I know the quirk is there, I copy the attributes and then check their definition. This does not happen all of the time and thus I cannot point to a sequence of events and say "There - that is how it happens - 100% guaranteed".

Perhaps related to this is also the fact that I cannot move rules "UP" the ladder but I can move them "DOWN" if they have attributes associated with them.

Thanks
D
fly.ing.fox
 
Posts: 13
Joined: Sat Apr 20, 2019 5:09 pm

If you want to reference a previously created attribute, you should drag it in. It will appear in the list of tokens you can drag in after the first definition. You can't re-create it (as it will think it's a new attribute and add a number to it as you've surmised).

Looks like the dragging up thing is a bug. Will look into it.
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Mr_Noodle wrote:If you want to reference a previously created attribute, you should drag it in. It will appear in the list of tokens you can drag in after the first definition. You can't re-create it (as it will think it's a new attribute and add a number to it as you've surmised).

Looks like the dragging up thing is a bug. Will look into it.


I think I mentioned that sometimes I do drag the attribute in from the list but it does not always copy the definition - it is blank.

So copy/paste I do not always get the definition and dragging (clicking) while defining I do not always get the definition transferring.

As for the dragging thing, it is not difficult to work around by simply creating the sub-rule below the rule you want to move and then dragging down. But yes, it should work both ways in a perfect world.

Where do I find a list of things you are working on for the app? I would love to see some features in the editing window, however I do not want to double up on someone else's suggestions or your planned upgrades (for example the ability to disable rules within a sequence).

Thanks
D
fly.ing.fox
 
Posts: 13
Joined: Sat Apr 20, 2019 5:09 pm

Why do you want the same definition in this case? Usually you re-use a custom attribute to provide a different definition.

No list of what I'm working on but you should always post your suggestions as even if it's been already mentioned, I use that as a vote for that feature. You can search the forums to see if there's already such a suggestion and reply to that post.
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Mr_Noodle wrote:Why do you want the same definition in this case? Usually you re-use a custom attribute to provide a different definition.


An example is the name of the file. Because I have a lot of emails that are named very similarly. I generate the UUID to ensure I do not get name clashes.

These emails are HTML emails and I save them as both EML and TXT - the EML is for archiving, while the TXT is for matching inside since the HTML is mostly a mess with no standardisation across multiple emails from the same source.

The (Date Field) is used in the AppleScript that is executed if all conditions are met for adding a Calendar event for the file - calculations are made on the (Date Field).

In the script I move the EML file to the archival directory as part of the cleanup and thus I need to pass the original file name into the script. Thus I need the original (Date Field) and (UUID) to generate the name of the file with an EML extension.

Deleting the TXT file is done within the Hazel rule itself since the rule can deal with the filename of the matched file.

Unless I am missing something and there is an easier way to both move an EML extension file while deleting a TXT extension file then that is why I am reusing Attributes with the same definition.

D
fly.ing.fox
 
Posts: 13
Joined: Sat Apr 20, 2019 5:09 pm

Are there other TXT files that you don't want to throw away? If not, then you could just remove the TXT files regardless of any pattern.
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

The problem with this idea is that I may receive 10+ emails all at once that dump their attachments into the processing directory - and they all have the same format file name (eml and txt).

My Hazel rule deals with a single file pair at a time - thus deleting all TXT files would not be appropriate in this case.

If the HTML in the email was more standardised - or if Mail allowed the printing of emails to PDF via AppleScript - then I would not run into this issue.

D
fly.ing.fox
 
Posts: 13
Joined: Sat Apr 20, 2019 5:09 pm

You might be able to do an AppleScript that simulates the inputs needed to do Print to PDF but it may be a bit clumsy/tricky to do.
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

The print to PDF solution for mail is more trouble than it is worth, especially with the processing of 10+ emails at a time.

You have to go through the standard "automate the clicks" method of AppleScript. And if anything takes the focus away from the window then *blech*!

Anyway, everything is working now and I have successfully run a full process on 100+ emails all at once which is what I wanted in the first place.

I have Hazel auto migrating all my media files, and my incoming invoices, and I am about to unleash it on my wife's 6-7 years of unsorted files.

D
fly.ing.fox
 
Posts: 13
Joined: Sat Apr 20, 2019 5:09 pm


Return to Support