Page 1 of 1

Waiting for several files to complete copying before running

PostPosted: Mon Nov 23, 2020 3:10 pm
by 0fox
Hi everyone

I'm trying to build a rule that runs an AppleScript to trigger another piece of software once copying a group of files into a folder is complete. I don't want the script to trigger ten times when copying ten files, I want to wait until the files are copied then run it once.

I feel like I am close to a solution using some comparison between the most recent added time and the current time, or something like setting a flag on a file if it's added time is among the most recent 1 and it's been more than five minutes, or something. But... I can't quite get there and it all feels a bit more complex than is sensible. So I think I must be missing something and thought I'd ask those with more experience to help. Usually with these things there is a much more elegant solution that has just passed me by.

I've only just upgraded to Hazel 5, so forgive me if I've missed something in the recent upgrade for this (I've mostly been trying to work this out in v4 but decided to upgrade as Hazel has been useful for years and it feels like time to pay a bit more!).

Open to any suggestions! Thanks :)

Re: Waiting for several files to complete copying before run

PostPosted: Mon Nov 23, 2020 4:17 pm
by Mr_Noodle
Problem is, Hazel does not know what a group of files is. Only the program copying them there does, so you need to figure out some coordination with that program. I guess you can try doing it by waiting for a gap but in the end, it's better if you can trigger it from the outside.

Re: Waiting for several files to complete copying before run

PostPosted: Mon Nov 23, 2020 4:29 pm
by 0fox
Thanks for the reply.
Yes I completely agree. I am trying to do something with Hazel that’s it’s not designed for.

In this case sadly I can’t do anything with the program copying, so I’m trying to make the least in-elegant Hazel workflow I can for it.

I have actually made some progress with this logic:

Rule 1
If file’s ‘added date’ is one of 1 most recent
then tag Red

Rule 2
If file’s ‘added date’ is not one of 1 most recent
then un-tag

Rule 3
If file’s ‘added date’ is not in the last 15 mins and the file is tagged Red then run AppleScript


Basically, the idea is only one file should be tagged red at any one time, and so the AppleScript should only run once.

This works in principal. But the problem I am now having is that since the upgrade Hazel is matching these rules (I can see with the preview) but isn’t actually acting on it. Or at least not for ten or fifteen minutes then it suddenly runs all at once.
Probably fixable with a restart, I just can’t do that at this moment as in the middle of something.

That aside, any bright ideas on how to improve my current option gratefully received.

Thanks everyone.

Edited to remove typo