I'm trying to create a simple workflow that will be used to help non-technical people use tesseract OCR. I have no problem using it myself, but others probably prefer GUIs, so I'm working on the following automator workflow (image below): https://drive.google.com/file/d/1nxiQVt7sQigQwgjpscG-0E9loCRO7Fxe/view?usp=sharing


set appName to "Terminal"

if application appName is running then
    tell application "Terminal"
        do script "tesseract /Users/jackson/Downloads/OCRTemp.jpg /Users/jackson/Downloads/OCRTemp.txt"
    end tell

    tell application "Terminal"
        do script "tesseract /Users/jackson/Downloads/OCRTemp.jpg /Users/jackson/Downloads/OCRTemp.txt" in front window
    end tell
end if

The problem is that in the line "tesseract /Users/jackson/Downloads/OCRTemp.jpg /Users/jackson/Downloads/OCRTemp.txt" I would like to replace the first file extension with the clipboard. Not being well versed in how to use bash, I'm not entirely sure what to do. I think part of the confusion is that I'm using an applescript to run a terminal command, so I'm not sure if I use applescript or terminal to get the variable.

Automator workflow


No need for Automator.

Just use AppleScript (Change /opt/local/bin/tesseract to the output of which tesseract):

set myFile to (choose file with prompt "Choose a file to convert") # Get the file to convert
set myFilePOSIX to the POSIX path of myFile # Get terminal friendly path
set myLocation to (choose folder with prompt "Choose a location to save your file") # Get location to save the file
set myLocationPOSIX to the POSIX path of myLocation
tell application "Finder"
    display dialog "Choose a file name" default answer (name of file myFile as string) # Type the name the file
    set myName to the text returned of the result # Get what user typed
end tell
do shell script "/opt/local/bin/tesseract " & quoted form of myFilePOSIX & " " & quoted form of myLocationPOSIX & quoted form of myName # Do the terminal command
  • Hmm.. Thank you. I tried that and I'm not sure why, but I'm getting the error: error "sh: /usr/local/bin/tesseract: No such file or directory" number 127 Is this because of where I've stored tesseract? – Talos Potential Jul 10 '18 at 15:10
  • @user279242 Yes. I can fix just run this command and post the output which tesseract – JBis Jul 10 '18 at 15:11
  • I assume you mean to terminal. Here's the output: /opt/local/bin/tesseract thanks for the help in advance. – Talos Potential Jul 10 '18 at 15:15
  • @user279242 Fixed. Try now. – JBis Jul 10 '18 at 15:17
  • 1
    Thanks! One last question. When I try PDFs, it says error "Tesseract Open Source OCR Engine v3.04.01 with Leptonica Error in pixReadMem: Pdf reading is not supported Error during processing." number 1 Does this basically mean I can't OCR PDFs? I can always do images if I have to - Never mind found this: github.com/tesseract-ocr/tesseract/issues/1476 thank you for your help. – Talos Potential Jul 10 '18 at 15:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .