date matched not being set after matching

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

Moderator: Mr_Noodle

date matched not being set after matching Tue Feb 20, 2018 10:14 pm • by TWSheppard
Under what circumstances will Hazel match a file with a rule, run an AppleScript specified by that rule that returns true, but fails to update the "Date Matched" field?

I'm using Hazel successfully to monitor many folders, including a huge iTunes Music folder without a problem.

However, when monitoring the ~/Library/Calendars/ folder for any changes to Info.plist or *.ics files, it fails to know a match has occurred and does not update the Date Matched field regardless of whether the script returns true or false. The folder is paused. I can preview the files (many!) within the nested subfolders and see the matching rule. I then tell Hazel to run the rules and I can watch the log to see all the files matching the rule. There is no indication of an error. I know the script is being run because if I return false, Hazel logs an error, but still does not update the preview field indicating there's been an error. (It also dumps the script as a huge hex encoded field of:
Code: Select all
OSAScriptErrorOffendingObjectKey = "<NSAppleEventDescriptor: 'scpt'($ ... $)>";
which is real nasty.)

When I then preview a file that had matched according to the log, the date matched field is blank and the file still thinks it matches the same rule. It doesn't help if I monitor a single .calendar folder with many events, but if I monitor a test calendar with a single event, it works fine. Is there something magical about the Calendars folder … or many files in a folder?

A related question is … since I'm debugging the script, I'd like to reset the Date Matched so that I can force a match again and run my script. The only way I can find to do that now is to delete the monitored folder and add it back, which is not fun, or to touch the file to change it's modification date, but that is undesirable. How can I reset the match status of one or all files?
TWSheppard
 
Posts: 5
Joined: Sat Nov 09, 2013 6:00 pm

Re: date matched not being set after matching Wed Feb 21, 2018 11:34 am • by Mr_Noodle
Hazel has to successfully run the actions on the rule. Has that happened?
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Mr_Noodle wrote:Hazel has to successfully run the actions on the rule. Has that happened?


I was under the false impression that once a script had been run on a file, that the Date Matched would be updated. But because there are thousands of calendar events, and I'm still debugging, at least one file script call would fail and I'd turn Hazel off to stop the rule to fix the bug in the script. Because the rule never ran to completion, no files were updated. So it's like a transaction.

To verify this, I modified the script so that the first line was "return true" and this time the Date Matched was updated when the rule completed a few minutes later. Thanks.

Which brings me to my next question. Is there a way to reset the Date Matched so I can force the scripts to be run again, other than deleting the folder, adding it back in, and importing the rules?
TWSheppard
 
Posts: 5
Joined: Sat Nov 09, 2013 6:00 pm

Re: date matched not being set after matching Thu Feb 22, 2018 11:21 am • by Mr_Noodle
If you remove the file (not everything else) and add it back in some time later, it should reset. Or for testing, you can add a condition to check a color label and then remove that color label. That way you can trigger a run by adding a color label to the file.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

This is a good option for one or two files, but does not scale to thousands of files nested in folders. At least for script debugging purposes, or when I add a new feature to a script, it would be nice to be able to reset the match date.
TWSheppard
 
Posts: 5
Joined: Sat Nov 09, 2013 6:00 pm

Re: date matched not being set after matching Fri Feb 23, 2018 11:46 am • by Mr_Noodle
How about checking the existence of another file in the folder? You can use a nested condition to match a file based on another one in the same folder.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support