Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Screenshot OCR with BetterTouchTool on MacOS
#!/usr/bin/env bash
# Usage:
# - Install `tesseract` with `brew install tesseract`
# - In BetterTouchTool, create a trigger of your choice.
# (I recommend a Keyboard Shortcut with Cmd+Shift 6)
# - Add an Execute Shell Script / Task action
# - Paste this script.
# NOTE: You'll need to authorize BTT to the Screen Recording permission in Security and Privacy at System Preferences
# When using this quick script, it'll use MacOS' screencapture tool, use tesseract for OCR and then pass the scanned
# text to your clipboard using pbcopy.
screencapture -i /tmp/tesseract.png && /opt/homebrew/bin/tesseract --dpi 72 /tmp/tesseract.png stdout | tr -d \\f | pbcopy
PREVIEW=`pbpaste | head -n 3`
# A one liner snippet is also provided via a notification.
osascript -e "display notification \"${PREVIEW}...\" with title \"OCR captured to clipboard.\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment