Page 1 of 1

Shell script only works in debug mode

PostPosted: Sun Mar 04, 2018 11:16 am
by general_relativity
Hi,

I try to run the following shell script in a Hazel rule:

Code: Select all
#!/bin/bash
/usr/local/bin/ocrmypdf --deskew --clean --rotate-pages "$1" "$1"


The script should use the open source tool ocrmypdf (https://github.com/jbarlow83/OCRmyPDF) to perform optical character recognition. In the terminal, the script runs fine. (The double "$1" is not a mistake, this means that the input file should be overwritten)
However, in Hazel it does not, I get the error "Shellscript exited with non-successful status code: 1".

Following advice in this forum, I enabled the debug mode to see if the logs would give a hint what is going wrong. Strangely enough, enabling the debug mode fixes the problem, the Hazel rule runs fine. When I disable debug mode, the script will fail again.

Does anyone have an idea what is wrong here? I would appreciate any help.

Cheers
Chris

Re: Shell script only works in debug mode

PostPosted: Mon Mar 05, 2018 11:54 am
by Mr_Noodle
I don't know much about this 'ocrmypdf' program but you should check to see what its different return codes are. In an ideal case, it should return precise error codes to help identify the problem though it could be the case it returns the same code for every error.

Re: Shell script only works in debug mode

PostPosted: Mon Mar 05, 2018 12:31 pm
by general_relativity
Hello and thanks for the reply.

That's what I tried, but I couldn't get any information. It seems that is always returns 1.
Do you have any idea why the script fails when debug mode in Hazel is turned off and succeeds when debug mode is turned on?

Re: Shell script only works in debug mode

PostPosted: Mon Mar 05, 2018 2:58 pm
by general_relativity
I found another workflow that works well for me :-)
However, if you have an idea why a script fails/succeeds dependent on the debug mode turned off/on, I would appreciate to hear that.

Cheers!

Re: Shell script only works in debug mode

PostPosted: Tue Mar 06, 2018 10:21 am
by Mr_Noodle
Only thing I can think of is that Hazel re-directs the stdout and stderr when in debug mode and if the script/program checks for that, it might behave differently.