Skip to content

Instantly share code, notes, and snippets.

Created May 22, 2021 13:32
  • Star 11 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
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.\""
Copy link

kewld00d commented Apr 2, 2023

For Intel Mac make sure to change location of Tessract - /opt/homebrew/bin/tesseract - in the script example above, to /usr/local/bin/tesseract You can make sure you have correct location by typing which tesseract in the Terminal and it will spit out the current install location on your computer for you , which you can then copy and paste and use to put in the script above. Should work great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment