Skip to content

Instantly share code, notes, and snippets.

@jerieljan
Created May 22, 2021 13:32
Show Gist options
  • Save jerieljan/f86843388c4ee9ecbc44d687a3b3dd27 to your computer and use it in GitHub Desktop.
Save jerieljan/f86843388c4ee9ecbc44d687a3b3dd27 to your computer and use it in GitHub Desktop.
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.\""
@kewld00d
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!

@fecundf
Copy link

fecundf commented Apr 17, 2024

For better treatment of curly-quotes and other UNICODE, add LANG=en_US.UTF-8 to the "Environment Variables" box in BetterTouchTool

@shredthaGNAR
Copy link

thanks! ill give it a try today. Thanks much appreciated

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