Skip to content

Instantly share code, notes, and snippets.

@pauljz
Last active February 12, 2016 16:57
Show Gist options
  • Select an option

  • Save pauljz/9590a38bcae9b53eceee to your computer and use it in GitHub Desktop.

Select an option

Save pauljz/9590a38bcae9b53eceee to your computer and use it in GitHub Desktop.

Revisions

  1. pauljz revised this gist Feb 12, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion auto-ocr.sh
    Original file line number Diff line number Diff line change
    @@ -27,4 +27,4 @@ while true; do
    echo "$OCR_TEXT"
    echo "$OCR_TEXT" | pbcopy
    fi
    done
    done
  2. pauljz revised this gist Feb 12, 2016. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion auto-ocr.sh
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,9 @@ 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')
    @@ -24,4 +27,4 @@ while true; do
    echo "$OCR_TEXT"
    echo "$OCR_TEXT" | pbcopy
    fi
    done
    done
  3. pauljz revised this gist Feb 12, 2016. 1 changed file with 11 additions and 7 deletions.
    18 changes: 11 additions & 7 deletions auto-ocr.sh
    Original file line number Diff line number Diff line change
    @@ -12,12 +12,16 @@ if ! hash fswatch 2>/dev/null; then
    fi

    while true; do
    OCR_TEXT=$(fswatch -1 ~/Desktop \
    | grep '/Screen Shot' \
    | xargs -I {} sh -c "convert '{}' -resize 300% -set colorspace Gray -separate -average -sigmoidal-contrast 10x60% ~/ss.tif | tesseract ~/ss.tif stdout")

    if [ "$OCR_TEXT" ]; then
    echo $OCR_TEXT | sed 's/ //g'
    echo $OCR_TEXT | sed 's/ //g' | pbcopy
    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
  4. pauljz revised this gist Feb 12, 2016. 1 changed file with 7 additions and 4 deletions.
    11 changes: 7 additions & 4 deletions auto-ocr.sh
    Original file line number Diff line number Diff line change
    @@ -12,9 +12,12 @@ if ! hash fswatch 2>/dev/null; then
    fi

    while true; do
    OCR_TEXT=$(fswatch -1 ~/Desktop | grep '/Screen Shot' | xargs -I {} tesseract {} stdout)
    OCR_TEXT=$(fswatch -1 ~/Desktop \
    | grep '/Screen Shot' \
    | xargs -I {} sh -c "convert '{}' -resize 300% -set colorspace Gray -separate -average -sigmoidal-contrast 10x60% ~/ss.tif | tesseract ~/ss.tif stdout")

    if [ "$OCR_TEXT" ]; then
    echo $OCR_TEXT
    echo $OCR_TEXT | pbcopy
    echo $OCR_TEXT | sed 's/ //g'
    echo $OCR_TEXT | sed 's/ //g' | pbcopy
    fi
    done
    done
  5. pauljz created this gist Feb 11, 2016.
    20 changes: 20 additions & 0 deletions auto-ocr.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #!/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

    while true; do
    OCR_TEXT=$(fswatch -1 ~/Desktop | grep '/Screen Shot' | xargs -I {} tesseract {} stdout)
    if [ "$OCR_TEXT" ]; then
    echo $OCR_TEXT
    echo $OCR_TEXT | pbcopy
    fi
    done