Skip to content

Instantly share code, notes, and snippets.

@shredthaGNAR
Forked from jerieljan/btt-screenshot.sh
Created August 9, 2022 10:04
Show Gist options
  • Select an option

  • Save shredthaGNAR/c2ba63bb0c4000ff79523b10fba97567 to your computer and use it in GitHub Desktop.

Select an option

Save shredthaGNAR/c2ba63bb0c4000ff79523b10fba97567 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 change location of Tessract - /opt/homebrew/bin/tesseract - in this script to /usr/local/bin/tesseract you can make sure you have correct location by typing which tesseract and it will spit out the installed location for you to put in the script

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