Hello!
I've got a series of macros that are triggered when a file is added to a folder. They trigger scripts using ffmpeg and is CPU heavy and takes around 2 hours to complete. This means if more than one file is added at the same time, it overloads the system.
My work around is to have a holding folder that the files get added into and at the end of the last macro I can action "if there are one or more .ogg files in /holding/, copy the first file in the directory to /processing/"
It means that in the first instance I would have to move a file across myself to trigger the initial macro but that's something I can deal with.
I imagine there is a scripted work around but unfortunately it's beyond my capabilities!
Any help would be more than welcomed.
Cheers
If I’m understanding your issue correctly, when adding more than one file, your macro is executing multiple times, causing the overload. If that’s the case, you could use a combination of a Semaphore Lock and For Each actions. Set the for each
to loop through each file in the directory and the semaphore lock
to a very fast timeout and cancel. Then it wouldn’t matter if you subsequently added more files as the semaphore lock would prevent the macro from fully executing again, but it would still loop through each one in the directly and do whatever you need.
Thanks for the reply.
Having read the wiki, I'm just trying to get my head round the process and think it could be quite simple..
I've got 4 macros each triggered by a file being added to a specific directory (file into folder1 triggers macro 1, that in turn encodes a file into folder2 which triggers macros 2 etc etc). If I was to use Semaphore Lock at the start of each macro -
When a file is added to the folder1, if (for example) macro3 is running, macro1 would be added to the queue as the next macro to be triggered? Then when macro3 is complete, macro4 will be added to the queue whilst macro1 is running?
Hopefully that's clear enough and that's the way it works, as that would be a fine solution!
It would be best to post your macro(s) in question, otherwise it’s just guess-work on our end. ![:wink: :wink:](https://forum.keyboardmaestro.com/images/emoji/apple/wink.png?v=12)
Thanks for the help so far, although I've realised the Semaphore solution wouldn't work..
As macro2 creates 6 different files, macro3 is triggered 6 times, the CPU can handle this but a Semaphore solution would slow the process down by a couple of hours.
My solution is to have files enter a holding folder as originally planned, and the final macro triggers the following -
Which whilst I haven't tested it, should move 1 file and cancel before the next, triggering the whole process again.
Edit -
As 6 versions of the final macros will run, I've added a variable counter that increases with each completion. When it reaches 6, that action is triggered and the counter is reset to 0.