Page 1 of 1

Manually Run Hazel Rule through AppleScript

PostPosted: Sun Nov 08, 2020 5:08 pm
by united
Hey,

I was wondering if there is a way to "run rules" on a specific folder through AppleScript?

The issue I'm having is:
I have rules in one folder1
- rule 1 is - pull all files that are ".jpg" and move them to folder1
- rule 2 is - move files (.jpg) to "external HD1" when available

This works 95% of the time but then sometimes I notice it doesn't work. But if I manually run the rules (hazel menu > run rules > folder1) on that folder again then it works as the previous times. So thought I could use an AppleScript with hazel to re-run the rules on the folder.

Re: Manually Run Hazel Rule through AppleScript

PostPosted: Mon Nov 09, 2020 10:41 am
by Mr_Noodle
I think it's better to look into why it isn't working. I suggest going through the troubleshooting guide here: https://www.noodlesoft.com/kb/hazel-tro ... ing-guide/

Report back with the results (you can email them if you like).

Re: Manually Run Hazel Rule through AppleScript

PostPosted: Thu Feb 12, 2026 5:05 pm
by united
So still bothering me.. thought I'd try again to get help...

This has been occurring since I can remember, this didn't occur in the between versions.

folder1
internal rule - if file is found with the specified extension move to folder1 root.
external rule - if file is found with the specified extension move to the external drive folder.

Rule Preview - matched the internal rule but then stopped at the rule and didn't go to match the external rule. If I add more files to this the file that didn't move reapplies the same rule.
View the Rule Status window - shows that it matched the internal rule but not the external rule
Check the logs - same as the above.

observation(s):
- that the "continue matching rules" is greyed out. so it seems like it stops there. Unsure why it is greyed out?
- the greyed out option is not selectable at all once you select something and attempt to select "continue matching rules" again.
- if you manually run the rule it works.
- if (issue which is sometimes), rule works to move files to the root folder
- if the drive is connected then the files are added the transfer works fine - always for new files added but not always for old files already there.

? - why does the "continue matching rules" greyed out?

- ex

-- folder1 is root
drive connected
---file dump1 - files transfer to folder1
---file dump2 - new files added to folder1 - always works
---file dump2 - new files files transfer to external drive - always works
---file dump1 - sometimes these get transferred to external drive / but if you manually run rule the files do get transferred over always

drive not connected
---file dump1 - files transfer to folder1
---drive connected
---file dump1 - files not transferred to external drive - see observations - this isn't always just sometimes - manually reprocessing folder transfer works as intended
--- stuck file - will only transfer if you rerun rules, move file out and place it back.

Unsure why the external rule doesn't run on this file even if the drive is connected, and root folder contents are modified.

Re: Manually Run Hazel Rule through AppleScript

PostPosted: Fri Feb 13, 2026 10:39 am
by Mr_Noodle
If you move a file out of the folder, it's not longer in the folder to be evaluated, hence why the Continue action is greyed out. Also, why are you doing two moves? Seems like a move to the final destination is all that is needed. It seems to me that you want to do a copy at some point instead.

Re: Manually Run Hazel Rule through AppleScript

PostPosted: Sat Feb 14, 2026 9:05 am
by united
Mr_Noodle wrote:If you move a file out of the folder, it's not longer in the folder to be evaluated, hence why the Continue action is greyed out. Also, why are you doing two moves? Seems like a move to the final destination is all that is needed. It seems to me that you want to do a copy at some point instead.


Agreed but the item isn't moved out of the root folder just moved out of the nested folders to the root folder. This is the internal move rule. I would agree to what you're saying for external but I dont' see why the internal move is greyed out.

No. Actually it's a move not a copy.

folder1 (root folder)
-- add folder or files in
-- internal move rule applies to move all the files to root folder
-- external move rule moves these files with extensions specified to external drive.

the issue is: the drive scenario
-- if drive is connected and the above is done. everything works as desired
-- sometimes not always, if the above done then the drive is connected, the external move doesn't occur. It keeps matching the internal rule, even if you force trigger root folder by adding more items like folders. still matches the internal rule. The only way to trigger the external rule is to run the rules on the folder1 using the menulet hazel pull down. Once this done then and only then does the external rule trigger.

This is why I'm trying get a way to trigger the rule so that I can script it based on the conditions I specify for this scenario.

hope that clarifies.

Re: Manually Run Hazel Rule through AppleScript

PostPosted: Mon Feb 16, 2026 10:09 am
by Mr_Noodle
Even if you are moving files to within the folder hierarchy, you should have it such that you have rules processing those separately. I still don't see why you need to do two moves here instead of moving directly to the final destination but if you insist on doing it this way, you need to have separate rules that process the file when they reach the root folder. You'll need to add conditions to distinguish between the two cases.

Re: Manually Run Hazel Rule through AppleScript

PostPosted: Thu Feb 19, 2026 1:54 am
by united
Mr_Noodle wrote:Even if you are moving files to within the folder hierarchy, you should have it such that you have rules processing those separately. I still don't see why you need to do two moves here instead of moving directly to the final destination but if you insist on doing it this way, you need to have separate rules that process the file when they reach the root folder. You'll need to add conditions to distinguish between the two cases.


1 move is when the drive isn't connected so if a folder with desired files exist that moves it to the root folder, another rule deletes everything else including the folder so the specified files are on the root folder ready to be moved to the external drive when connected.
2 move is the external drive is connected it'll move it there

thats what I'm sharing. I have done that.
- rule 1 - internal move (move 1 conditions)
- rule 2 - external move (move 2 conditions)

The inconsistency is unclear why when drive is connected rule 1 and rule 2 work. When the drive is not connect only rule 1 runs with files moved to the root and sometimes rule 2 runs when the drive is connected, other times rule 2 doesn't run and rule 1 is only matched. However, if you run the rule 2 manually with the drive connected rule 2 runs and moves that file that previously didn't move.

hope that clarifies..

Re: Manually Run Hazel Rule through AppleScript

PostPosted: Thu Feb 19, 2026 9:59 am
by Mr_Noodle
I think that actually makes it more confusing.

If rule 1 moves the file to root, the file is in another place. Is rule 2 active there to move it to the new location? How about instead of moving it to root, you move it to another folder entirely and have rule 2 set up on that folder?

Have you gone through the troubleshooting guide? (https://www.noodlesoft.com/kb/hazel-tro ... ing-guide/)

Re: Manually Run Hazel Rule through AppleScript

PostPosted: Thu Feb 19, 2026 5:54 pm
by united
Mr_Noodle wrote:I think that actually makes it more confusing.

If rule 1 moves the file to root, the file is in another place. Is rule 2 active there to move it to the new location? How about instead of moving it to root, you move it to another folder entirely and have rule 2 set up on that folder?

Have you gone through the troubleshooting guide? (https://www.noodlesoft.com/kb/hazel-tro ... ing-guide/)


There are multiple use cases here that this workflow accomplishes. To help clarify further, as shared previously rule 1 when files/folders are placed in the root folder rule 1 goes moves the specified files to the root if they are already at the root level it tags them so not to repeatedly be processed. Another rule goes to the subfolder to apply all the rules to subfolder. Rule2 Moves the files to the external drive when the external drive is detected. Rule 2 is doing that moving it to the external drive where a different folder resides.

The greater issue is not the work flow but why the hazel inconsistency in execution and how to alleviate that issue of the rule 1 running consistently. But rule 2 not running sometimes on some files based on whether the drive is connected or not. But it does work as expected if you manually run the rules through the menulet menu when this scenario occurs. Also, works as expected if the drive is connected and then folders/files are added and processed as desired, rule 1 runs then rule 2. Hence the request to trigger the rule through AppleScript.

Yes. I have used the troubleshooting guide: To test it I have added files/folders for it to process both with connected/unconnected drive.

Rule Preview: Shows rule 1 matched when the drive is not connected. Holding off in doing this when the drive is connected assuming it will trigger rule 2 since it might be like running the rules through the menulet and will work.
Rule Status window: show the matched rule seconds after items are added to the root folder.
Check the logs: It seems to match rule 1 never to go to rule 2.

The core issue is.
1 - Why rule 2 doesn't run at times based on when items are added with or without the drive connected.
2 - whey rule 2 doesn't re-run on the file again when the drive is connected on files. Even when adding new files or not adding new files again?

If you move a file out of the folder, it's not longer in the folder to be evaluated, hence why the Continue action is greyed out.


This might be another alternative. you share it's no longer needed. But there are scenarios where having the control to allow it to continue process items in the root folder is needed. This being one. IT seems that the rule 1 can't continue matching rules like rule 2 since the "Continue matching rules" is greyed out. I might recalled where this feature was at the user's discretion in hazel early releases. Allowing it at the user's discretion would be something I feel might resolve this issue.

hope this helps to clarify. Since we have discussed this I feel sufficiently. What might be a solution for hazel to handle this? I've shared my observations and suggestions. Would greatly appreciate a solution for this use case.

Re: Manually Run Hazel Rule through AppleScript

PostPosted: Fri Feb 20, 2026 10:53 am
by Mr_Noodle
Things will just break if you leave to user discretion and that would also result in extra confusion and support.

If the file is not matching rule 2, then you need to do the troubleshoot that aspect. Does the file match rule 2 after being moved by rule 1? Why not? If it does match, then you need to dig further to figure out why. Please post the results.

Re: Manually Run Hazel Rule through AppleScript

PostPosted: Fri Feb 20, 2026 9:07 pm
by united
Mr_Noodle wrote:Things will just break if you leave to user discretion and that would also result in extra confusion and support.

If the file is not matching rule 2, then you need to do the troubleshoot that aspect. Does the file match rule 2 after being moved by rule 1? Why not? If it does match, then you need to dig further to figure out why. Please post the results.


Agreed. But there are users then there are users.

No. The rule 2 works but rarely it doesn't as shared in the scenario above. I welcome a suggestion in the scenario posted to isolate the issue. Both rules work when manually ran, in the scenario above. The only difference is that the drive is connected. Why it stops on rule 1 and not proceed to rule 2, that is the issue. Any insight would be appreciated.