#!/bin/sh
# $Source: /afs/sipb.mit.edu/project/scanner/src/adfscan/RCS/adfscan,v $
# $Id: adfscan,v 1.4 2005/04/25 04:28:19 jhawk Exp $
#
# adfscan -- a poorly named script to manage scanning files on SIPB's
# Epson 1640SU w/ document handler.

# Choose a tag for filenames. Use $1 if specified, otherwise pid.
case "$1" in
"") tag=$$ ;;
*)  tag="$1" ;;
esac

# Create a script to convert the files to png.
# If the filename already exists (derived from the tag), then
#   don't  blow it away.
script="/var/tmp/$USER.$tag.sh"
if [ ! -f "$script" ]
then
  cat <<'EOF' >"$script"
#!/bin/sh
# generated from: $Id: adfscan,v 1.4 2005/04/25 04:28:19 jhawk Exp $
#
# It's sort of questionable whether it is a good idea to rnu convert in
# the background. It does a good job when the files are relatively small,
# but can really bog things down if the files are mammoth.
convert -verbose $1 $1.png &
EOF
  chmod a+x "$script"
fi

# Here we assume 300dpi grayscale. Maybe not the best choice, but it was
# right for what I'm doing right now. command-line? UI? feh. Really
# we need to couple it to xscanimage's preview feature, assuming it saves
# the right data in ~/.scane/xscanimage/xscanimage.rc...
#
# --eject does not seem to work.
athrun scanner scanadf \
  --mode Gray \
  --resolution 300 \
  --quick-format Letter \
  --source 'Automatic Document Feeder' \
  --output-file "/var/tmp/$USER.$tag.p%03d" \
  --scan-script "$script" \
  --eject
 
# eject the last page:
scanimage -L
