Run OCR / Text Recognition On Selected Area On Screen

This could be a timing issue. Maybe the short time (few ms) it takes to run the "Enable Clipboard Observation" action is already long enough for the clipboard to change, thus no further change would happen.

I'll do some experiments with Teams. Microsoft apps always do very special clipboard management.

1 Like

Is there any way to ensure this doesn't interfere with Clop?
I have set up the Clop app to copy the screenshot to the clipboard.
When I perform this preset shortcut, it triggers Clop, and the result I'm getting is only the screenshot, not text.

Sorry I have no idea what Clop does or how it would interfere. Maybe you can disable it before using this action.

clop is a optimiser tool,
whenever i copy any image/video or take a screenshot it automatically optimise the file and copies to the clipboard

I'd disable this for this scenario, OCR works best on the raw image data captured.

You could probably make it work somehow by adding a delay after the screenshot capture action.

Nah, it's not working. I use Clop very frequently, and to grab text from images, I use the TextSniper app. I wish I could replace TextSniper with this OCR tool.

1 Like

Step-by-Step: Setting Up an OCR + QR Script Workflow in BetterTouchTool using Tessaract OCR Engine


Step 1: Install Homebrew (if not already installed)

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Step 2: Install Tesseract OCR

brew install tesseract

Step 2a (Optional): Install additional Tesseract languages

brew install tesseract-lang

Tesseract language data will be in /opt/homebrew/share/tessdata/ (Apple Silicon Macs) or /usr/local/share/tessdata/ (Intel Macs).


Step 3 (Optional): Install zbar for QR code recognition

brew install zbar

Step 4: Check installation paths

which tesseract
which zbarimg

You should see output like /opt/homebrew/bin/tesseract.


Step 5: Add your script to BetterTouchTool

  • Open BetterTouchTool and go to your preferred trigger section (e.g., Keyboard Shortcut, Trackpad Gesture).
  • Click "Add New Trigger" and set your shortcut or gesture.
  • For the action, select "Run Shell Script / Task."
  • Paste your script. Example script below:
#!/bin/zsh
export PATH="/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
LANGS="eng"
ocr_dir="$HOME/.ocr_temp"
mkdir -p "$ocr_dir"
timestamp=$(date +%s)
run_dir="$ocr_dir/run_${timestamp}"
mkdir -p "$run_dir"
img_file="$run_dir/screencap.png"
txt_file="$run_dir/out.txt"
/usr/sbin/screencapture -i "$img_file" || exit 1
qr_output=$(zbarimg --quiet --raw "$img_file" 2>/dev/null)
if [[ -n "$qr_output" ]]; then
    echo "$qr_output" | pbcopy
else
    tesseract "$img_file" "$txt_file" -l $LANGS >/dev/null 2>&1
    awk -v ORS="" '
        BEGIN{para=""}
        {
          if (NF==0) {
            if (para!="") print para "\n\n";
            para="";
          } else {
            if (para=="") para=$0;
            else para=para " " $0;
          }
        }
        END{if (para!="") print para}
    ' "${txt_file}.txt" | iconv -f UTF-8 -t UTF-8 | pbcopy
    rm -f "${txt_file}.txt"
fi
rm -f "$img_file"

Step 6: Usage

  • Invoke your BTT gesture or shortcut.
  • Select an area on your screen.
  • The extracted text or QR code link will be copied to your clipboard, ready to paste anywhere.
2 Likes