Announcement: Upgrade to macOS Mojave

With features like Dark Mode, Stacks, and four new built-in apps, macOS Mojave helps you get more out of every click. 
Find out how to upgrade to macOS Mojave > https://support.apple.com/macos/mojave

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Question:

Question: Ascii vs. Utf-8 when Running Shell Scripts in Automator...?

I am trying to run ocrmypdf (a command-line implementation of Tesseract) in Automator (currently as a workflow, and once debugged, as an app). I can run ocrmypdf in termal, but in Automator, I get an error stating:


"RuntimeError: ocrmypdf will abort further execution because Python 3 was configured to use ASCII as encoding for the environment."


I have adapted instructions from another shell script. The ocrmypdf version reads:


for f in "$@"

do

suffix="-eng-ocred.pdf"

base=`basename "$f" .pdf`

outputfile=$base$suffix

/usr/local/bin/ocrmypdf --force-ocr "$f" "$outputfile"

done


Some online sources suggest using environment variables LC_ALL and LANG; in this case both would be en_US.UTF-8 but I couldn't get these to work, and other sources state these are specific to Linux proper and don't work in MacOS.


Any idea how to avoid this bug in automator?


If I can get this fixed, I will probably set up different apps for different languages. I don't know how to query myself for the appropriate language.

MacBook Air (11-inch Mid 2013), macOS Sierra (10.12.6)

Posted on

Reply
Question marked as Helpful

Mar 10, 2018 11:40 AM in response to Marja E In response to Marja E

Hi Marja,


In the Terminal, the locale(1) command will show everything set as "en_US.UTF-8," or your localized country code. In the Automator Run Shell Script, locale will report "C."


Try setting export LANG=en_US.UTF-8 (or your appropriate country code) at the beginning of your Run Shell Script action, and see if ocrmypdf sniffs out that environment variable setting, and tells Python to do UTF-8 instead of ASCII.

There’s more to the conversation

Read all replies

Page content loaded

Question marked as Helpful

Mar 10, 2018 11:40 AM in response to Marja E In response to Marja E

Hi Marja,


In the Terminal, the locale(1) command will show everything set as "en_US.UTF-8," or your localized country code. In the Automator Run Shell Script, locale will report "C."


Try setting export LANG=en_US.UTF-8 (or your appropriate country code) at the beginning of your Run Shell Script action, and see if ocrmypdf sniffs out that environment variable setting, and tells Python to do UTF-8 instead of ASCII.

Mar 10, 2018 11:40 AM

Reply Helpful (1)
User profile for user: Marja E

Question: Ascii vs. Utf-8 when Running Shell Scripts in Automator...?