Compare commits

..

No commits in common. "498aba165eebf9e1fea0c1ef62f5b5de0c94fa5a" and "74c94ef6581ad7131e13a00ba800ed658f7c6cc8" have entirely different histories.

2 changed files with 26 additions and 58 deletions

1
.gitignore vendored
View file

@ -1 +0,0 @@
*.pdf

View file

@ -1,90 +1,59 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# device="brother5:bus2;dev2" brother_opts=()
device=$(scanimage -f "%d%n" | grep brother5 | head -n 1) scanner_mode='Black & White'
echo "Selecting scanner '$device'"
# option values for the brother DS-740D scanner
simplex_source='Automatic Document Feeder(left aligned)'
duplex_source='Automatic Document Feeder(left aligned,Duplex)'
color_mode='24bit Color[Fast]'
bw_mode='Black & White'
grayscale_mode='True Gray'
valid_resolutions=("100" "150" "200" "300" "400" "600" "1200")
# default options for scanning
sides=$simplex_source
mode='c'
resolution='300' 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); current_page=$(find "$PWD" -name "out*.pdf" | sort | tail -n 1);
read -r current_pageno <<<"${current_page//[^0-9]/ }" read -r current_pageno <<<"${current_page//[^0-9]/ }"
current_pageno=${current_pageno:-0} current_pageno=${current_pageno:-0}
last_out_file="out$current_pageno.pdf"
next_out_file="out$((current_pageno+1)).pdf" next_out_file="out$((current_pageno+1)).pdf"
scan() { scan() {
usage() { while getopts "dr:" flag; do
echo "scanbuddy.bash scan -d -r <resolution($resolution)> -b <c|b|g>"
}
while getopts "dr:c:" flag; do
case ${flag} in case ${flag} in
d) d)
echo "Scanning duplex" echo "Scanning duplex"
sides=$duplex_source source=$duplex_source
;; ;;
r) r)
echo "Resolution=$OPTARG"
if [[ ! " ${valid_resolutions[*]} " =~ [[:space:]]${OPTARG}[[:space:]] ]]; then if [[ ! " ${valid_resolutions[*]} " =~ [[:space:]]${OPTARG}[[:space:]] ]]; then
echo "Resolution '$OPTARG' not supported!" echo "Resolution not supported"
echo "Supported resolutions: $(printf %s "${valid_resolutions[*]}")"
exit 1 exit 1
fi fi
resolution=$OPTARG
;; ;;
c) b)
mode=$OPTARG echo "Black and white";
;; ;;
*) *)
;; ;;
esac esac
done done
case $mode in
c)
scanner_mode=$color_mode
;;
b)
scanner_mode=$bw_mode
;;
g)
scanner_mode=$grayscale_mode
;;
*)
echo "Mode '$mode' not supported! Supported modes: (c)olour|(b)lack & white|(g)reyscale"
;;
esac
echo "Scanning to '$next_out_file'..."
scanimage \
--device-name=$device \
--format=pdf \
--output-file="$next_out_file" \
--mode="$scanner_mode" \
--resolution="$resolution" \
--source="$sides" \
-x 210 -y 297 # A4
} }
case "$1" in case "$1" in
scan) scan)
scan "${@:2}" scan "${@:2}"
;; exit 0
unscan)
rm "$current_pageno" if [ "$2" = "duplex" ]; then
;; true
dispatch) 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" echo "Usage: scanbuddy"