Shell commands work in Terminal but not in Automator service

automatorcommand line

I try to implement these two very simple commands in an Automator service to be run by a keyboard short (takes a screenshot and OCRs it):

screencapture -i /tmp/tesseract.png
tesseract /tmp/tesseract.png stdout|tr -d \\f|pbcopy

This works great when I execute these commands in the Terminal, but not when I make it an Automator service (sorry this is in German).
Automator window
I don't understand: Why does it work in the one case and not in the other? Does it have anything to do with tesseract?

Best Answer

Any executable that is not within the PATH passed to the Run Shell Script action, which is /usr/bin:/bin:/usr/sbin:/sbin, you must use the fully qualified pathname of the executable.

In this case, e.g. /path/to/tesseract

You should be able to get its path in Terminal using:

which tesseract

As tesseract is not a default of macOS, it may be in /usr/local/bin/, however which tesseract should report its fully qualified pathname.

Instead of using the fully qualified pathname, or in conjunction with, you can also add a PATH statement to the top of the Run Shell Script action, e.g. for a bash shell:


You could also just substitute everything to the right of the = sign for what the output in Terminal, e.g. echo $PATH is. Then the Run Shell Script action has the same PATH as Terminal.