scanbuddy/scanbuddy.bash
2025-09-21 21:51:54 +02:00

61 lines
1.3 KiB
Bash
Executable file

#!/usr/bin/env bash
brother_opts=()
scanner_mode='Black & White'
resolution='300'
source='Automatic Document Feeder(left aligned)'
duplex_source='Automatic Document Feeder(left aligned,Duplex)'
device="brother5:bus4;dev3"
valid_resolutions=("100" "150" "200" "300" "400" "600" "1200")
current_page=$(find "$PWD" -name "out*.pdf" | sort | tail -n 1);
read -r current_pageno <<<"${current_page//[^0-9]/ }"
current_pageno=${current_pageno:-0}
next_out_file="out$((current_pageno+1)).pdf"
scan() {
while getopts "dr:" flag; do
case ${flag} in
d)
echo "Scanning duplex"
source=$duplex_source
;;
r)
echo "Resolution=$OPTARG"
if [[ ! " ${valid_resolutions[*]} " =~ [[:space:]]${OPTARG}[[:space:]] ]]; then
echo "Resolution not supported"
exit 1
fi
;;
b)
echo "Black and white";
;;
*)
;;
esac
done
}
case "$1" in
scan)
scan "${@:2}"
exit 0
if [ "$2" = "duplex" ]; then
true
fi
# cat <<EOF
echo "Scanning to '$next_out_file'..."
scanimage --device-name=$device --format=pdf --output-file="$next_out_file" \
--mode="$scanner_mode" --resolution="$resolution" \
--source="$source"
;;
*)
echo "Usage: scanbuddy"
;;
esac