Shell script only works in debug mode

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

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
general_relativity
 
Posts: 3
Joined: Sun Mar 04, 2018 11:09 am

Re: Shell script only works in debug mode 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.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

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?
general_relativity
 
Posts: 3
Joined: Sun Mar 04, 2018 11:09 am

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!
general_relativity
 
Posts: 3
Joined: Sun Mar 04, 2018 11:09 am

Re: Shell script only works in debug mode 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.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support