Page 1 of 1

Actions not waiting for previous action to complete.

PostPosted: Fri Jan 13, 2017 6:25 pm
by alpatti
I have a simple rule that runs a shell script and marks the file with a red tag.

I expected that the shell script would need to run successfully before marking the file with the red tag. What I see as I watch the directory with all the files to be processed is that all the files receive the red tag long before the shell script has run.

Why?

I would have a lot more confidence in the process, if the red tag did not get set until after the shell script had successfully completed. Now my only check is to count the files in the source directory vs the destination directory to make sure that match.

Re: Actions not waiting for previous action to complete.

PostPosted: Mon Jan 16, 2017 2:49 pm
by Mr_Noodle
Actions execute in sequence. What does the script do and how are you sure it isn't running? Can you post the script?

Re: Actions not waiting for previous action to complete.

PostPosted: Mon Jan 16, 2017 10:24 pm
by alpatti
Hazel actions are

Run shell script OCRaPDF
Set color label red

script OCRaPDF
#!/bin/bash
open -a "PDF OCR" $1

While monitoring the directory where the PDFs are located, I "Run Rules Now". In a matter of seconds ALL of the files have a red label, but i takes several minutes for ALL of the files to be OCRd.

I expected the actions to executed in sequence, but that is not the behavior I am seeing.

Re: Actions not waiting for previous action to complete.

PostPosted: Tue Jan 17, 2017 1:10 pm
by Mr_Noodle
The "open" command in this case is asynchronous. What that means is that it returns before it completes, which it does in its own thread of execution.

I would recommend instead using AppleScript to interface with the "PDF OCR" program. You may have to put in a wait loop there. If you search the forums here, you can find AppleScripts to drive other OCR programs which you can use as a starting point.