#!/bin/bash #You can change the resolution or the scanmode adding commandline arguments #"buchscan resolution mode" is the syntax #Defining standard options model=epson #your printer model stdresolution=240 #your default resolution stdmode=gray #your default scanmode stdauthor=$USER #default author of the pdf file stdsub="" #default subject for the pdf file stdkeywords="" #default keywords for the pdf file stdtitle="" #default title for the pdf file #Change directory to store tempfiles and outputfiles cd /tmp help() { echo "known options" echo "-h This helptext" echo "-r set resolution" echo "-m set mode" echo "-a set author" echo "-s set subject" echo "-k set keywords" echo "-t set title" exit 0 } findscanner() { #Find the scanner via scanimage -L and cut out the device name scanimage -L | sed -e "s/.*\`\([^']\+\)'.*/\1/" | grep $model } files() { ls /tmp/out*.tif } while [ -n "$1" ]; do case $1 in -h) help;shift 1;; -r) resolution=$2;shift 2;; -m) mode=$2;shift 2;; -a) author=$2;shift 2;; -s) sub=$2;shift 2;; -k) keywords=$2;shift 2;; -t) title=$2;shift 2;; -*) echo "error: no such option $1.";exit 1;; *) break;; esac done if [ -z "$resolution" ] then resolution=$stdresolution fi if [ -z "$mode" ] then mode=$stdmode fi if [ -z "$author" ] then author=$stdauthor fi if [ -z "$sub" ] then sub=$stdsub fi if [ -z "$keywords" ] then keywords=$stdkeywords fi if [ -z "$title" ] then title=$stdtitle fi #Finding Scanner echo "Finding Scanner..." scanner=`findscanner` if [ -z "$scanner" ] then echo "No Scanner found" exit 0 else # Scan Images scanimage --device=$scanner --batch=out%d.tif --batch-start=11 --wait-for-button=yes --resolution=$resolution --format=tiff --mode $mode fi #looking for created files file=`files` #if [ -z "$file" ] #then #echo "No data found" #exit 0 #fi #Create one big TIFF echo "Combining TIFF images..." tiffcp -c lzw out*.tif document.tif # Create PDF echo "Creating PDF document..." tiff2pdf -z document.tif -o document.pdf -a "$author" -t "$title" -s "$sub" -k "$keywords" #echo "Optimizing PDF..." pdfopt document.pdf document_opt.pdf #echo "Cleaning up..." rm out*.tif rm document.tif rm document.pdf cp document_opt.pdf $HOME rm document_opt.pdf