# This is here because scanimage's batch mode is broken for my scanner OUTPUT_FILE="${1:-./scan_"$(date)".pdf}" tempdir="$(mktemp -d)" counter=1 while :; do # If no size is set, the output will be wonky-sized # 210,297 is the size of A4 scanimage -x 210 -y 297 --resolution 300 -o "$tempdir/easyscan_$counter.pdf" || { echo "Failed to scan page..." } IFS= read -r -p "Continue scanning? [Y/n] " cont case "$cont" in [nN]) echo "Exiting..." break ;; [yY] | *) ;; esac counter=$((counter += 1)) done # Multiple files are scanned, join them merged_filename="$tempdir/easyscan_final.pdf" pdfunite "$tempdir"/*.pdf "$merged_filename" # Copy scan to current directory cp "$merged_filename" "$OUTPUT_FILE" # Make sure I don't remove things other than pdf rm "$tempdir/"*.pdf rm -d "$tempdir"