"File not found" when running command-line tools in Automator

I often use ocrmypdf --force-ocr --output-type pdfa-1 input.pdf output.pdf in order to ocr pdfs. But it's tedious typing in all the terms every time, so it's a good candidate for Automator.


Based on another script, I tried:


Application receives files and folders as input > Run shell script


Shell:/bin/bash Pass input: as arguments


for f in "$@"

do

suffix="-OCRA1.pdf"

base=`basename "$f" .pdf`

outputfile=$base$suffix

/usr/local/bin/ocrmypdf --force-ocr --output-type pdfa-1 $@ "$outputfile" "$f"

done


I keep getting an error saying that Automator was unable to find tesseract. It is in /usr/bin where ocrmypdf usually has no trouble calling it.


I don't know what's going wrong or what can fix it.

Mac mini 2018 or later

Posted on Jan 29, 2019 3:10 PM

Reply

Similar questions

2 replies

Jan 29, 2019 3:53 PM in response to Marja E

Automator runs in a limited environment.

printenv: SHELL=/bin/bash
                  TMPDIR=/var/folders/zv/zvU6+bMiHTeElG+JIWOdzk+++TI/-Tmp-/
                  Apple_PubSub_Socket_Render=/tmp/launch-rVMvHQ/Render
                  USER=<me>
                  COMMAND_MODE=unix2003
                  SSH_AUTH_SOCK=/tmp/launch-fH4Gt7/Listeners
                  __CF_USER_TEXT_ENCODING=0x1F5:0:0
                  PATH=/usr/bin:/bin:/usr/sbin:/sbin
                  PWD=/Users/<me>
                  DBUS_LAUNCHD_SESSION_BUS_SOCKET=/tmp/launch-RIPIu6/unix_domain_listener
                  SHLVL=1
                  HOME=/Users/<me>
                  LOGNAME=<me>
                  DISPLAY=/tmp/launch-ttdbVO/org.x:0
                  _=/usr/bin/printenv


If ocrmypdf expects an environment variable that is not in the minimum environment or a program that is not in PATH, then your Automator script will fail.


You could try checking the man page for ocrmypdf to see if it has some environmental requirements and arrange for those to be set in your script before invoking it.



Jan 29, 2019 3:50 PM in response to Marja E

export PATH=/usr/local/bin:$PATH
for f in "$@"
do
	suffix="-OCRA1.pdf"
	base=`basename "$f" .pdf`
	outputfile=$base$suffix
	/usr/local/bin/ocrmypdf --force-ocr --output-type pdfa-1 $@ "$outputfile" "$f"
done


Tesseract should be in /usr/local/bin. Not sure why you have $@ after pdfa-1, or if it is necessary, then perhaps enclosing it in quotes for any white-space files that are passed into the action.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

"File not found" when running command-line tools in Automator

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.