Skip to content

Instantly share code, notes, and snippets.

@pauljz
Last active February 12, 2016 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pauljz/9590a38bcae9b53eceee to your computer and use it in GitHub Desktop.
Save pauljz/9590a38bcae9b53eceee to your computer and use it in GitHub Desktop.
#!/bin/bash
# Install homebrew and dependencies if missing...
if ! hash brew 2>/dev/null; then
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
if ! hash tesseract 2>/dev/null; then
brew install tesseract
fi
if ! hash fswatch 2>/dev/null; then
brew install fswatch
fi
if ! hash convert 2>/dev/null; then
brew install imagemagick
fi
while true; do
SCREENSHOT=$(fswatch -1 ~/Desktop | grep '/Screen Shot')
if [ "$SCREENSHOT" ]; then
echo "Running OCR on $SCREENSHOT..."
convert "$SCREENSHOT" -resize 300% -set colorspace Gray -separate -average -sigmoidal-contrast 10x60% ~/ss.tif
OCR_TEXT=$(
tesseract ~/ss.tif stdout 2> /dev/null |
sed 's/ //g' | # Remove spaces
sed 's/O/0/g' # Replace O with 0
)
echo "$OCR_TEXT"
echo "$OCR_TEXT" | pbcopy
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment