Skip to content

Instantly share code, notes, and snippets.

@jiphex
Created January 16, 2011 23:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jiphex/782274 to your computer and use it in GitHub Desktop.
Save jiphex/782274 to your computer and use it in GitHub Desktop.
Scans a document from the default scanner and emails it (securely) via GMail
#! /usr/bin/env bash
# scans a single document and mails it
#
# Requirements: sane, ImageMagick, tesseract, gocr, sendemail
# It would be trivially email to remove gocr, tesseract is better it seems
# You could replace ImageMagick with anything that convert PBM > something.
SCANFILE=`mktemp /tmp/scantmp.XXXXXXXX`
PBMFILE="${SCANFILE}.pbm"
TIFFILE="${SCANFILE}.tif"
GOCRTXT="${SCANFILE}.gocr.txt"
TESSTXT="${SCANFILE}.tess"
OUTTXT="${SCANFILE}.msg"
JPGFILE="${SCANFILE}.jpg"
echo "Scanning to ${SCANFILE}.pbm..."
scanimage --mode=color > $PBMFILE
convert $PBMFILE $TIFFILE
convert $PBMFILE -quality 60% $JPGFILE
tesseract $TIFFILE $TESSTXT
TESSTXT="${TESSTXT}.txt"
gocr -i $PBMFILE -o $GOCRTXT
cat > $OUTTXT <<EOF
Hi,
I've scanned a document, the OCR text and JPEG image are attached below.
Regards,
Scanmatic.
----- BEGIN TESS TEXT -----
`cat $TESSTXT`
----- END TESS TEXT -----
----- BEGIN GOCR TEXT -----
`cat $GOCRTXT`
----- END GOCR TEXT -----
EOF
sendemail -s smtp.gmail.com:587 -o message-file=$OUTTXT -a $JPGFILE -t you@gmail.com -u "Document Scan `date`" -f you@gmail.com -o tls=yes -xu you@gmail.com -xp y0urGm4ilp4ssw0rd
rm -vf $PBMFILE $TIFFILE $GOCRTXT $SCANFILE $TESSTXT $OUTTXT $JPGFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment