DT3 check PDF/A scan

That works in Terminal:

/usr/local/bin/pdfinfo -meta x.pdf | /usr/bin/grep pdfa > /dev/null 2>&1	
if [ $? -ne 0 ]
	then
  	echo "0"
    	exit 1
fi
echo "1"

with result “1” for PDF/A and “0” for PDF.

But with automator:

/usr/local/bin/pdfinfo -meta "$1" | /usr/bin/grep pdfa > /dev/null 2>&1	
if [ $? -ne 0 ]
	then
  	echo "0"
    	exit 1
fi
echo "1"

… an error occurs only for non-PDF/A files:

2021-11-17 um 21.22.35

Please disregard and see DT3 check PDF/A scan - #22 by chrillek for an explanation

My oh my, this error message is so beautiful in its uselessness. Worth of printing, framing and putting on the wall of every Automator fan.

Now that that’s off my chest: one solution might be to stuff all commands in a file, make it executable and pass that to Automator for execution (assuming it knows how to do that).

Alternative: replace the newlines in the command with semicolons.

Alternative: enclose if part in single quotes.

But I really don’t know what Automator can and cannot do. I’ve never used it, apparently for good reason.

1 Like

Running this code in Automator with zsh as shell works just fine. But it is, of course, not the same code as yours (see below for that).

grep jxa /Users/MySelf/Develop/.../config.toml 1>/dev/null 2>&1
if (( $? ))
then
  echo "wrong"
else
  echo "right"
fi

Similarly, using [ $? -eq 0 ] in the if condition and running the stuff in bash works ok here (i.e. no error message at all). So something else is wrong at your side.

And that is the exit 1 in your script. It does EXACTLY the same as grep when it 's not finding the string you’re looking for, namely raise an error.

I frankly do not get it: If you already have an error by grep, why would you raise another one in your if? The whole point of the if ... else... fi was to return a string to Automator that you could then maybe work with. There’s no f*ing need to use exit here, just go with an if ... else ... fi. That’s why the gods of programming invented these statements.

It is not really helpful if you change code without saying so and then state that it does not behave as advertised.