Compare commits

..

4 commits

Author SHA1 Message Date
Prunebutt
498aba165e add unscan and dispatch command 2025-09-22 12:02:44 +02:00
Prunebutt
1391b72c26 add geometry 2025-09-22 00:22:42 +02:00
Prunebutt
d7a3114893 cleanup code 2025-09-21 22:39:47 +02:00
Prunebutt
a786b9ef32 add more options to scanning 2025-09-21 22:38:29 +02:00
2 changed files with 58 additions and 26 deletions

1
.gitignore vendored Normal file
View file

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

View file

@ -1,59 +1,90 @@
#!/usr/bin/env bash #!/usr/bin/env bash
brother_opts=() # device="brother5:bus2;dev2"
scanner_mode='Black & White' device=$(scanimage -f "%d%n" | grep brother5 | head -n 1)
resolution='300' echo "Selecting scanner '$device'"
source='Automatic Document Feeder(left aligned)'
# option values for the brother DS-740D scanner
simplex_source='Automatic Document Feeder(left aligned)'
duplex_source='Automatic Document Feeder(left aligned,Duplex)' duplex_source='Automatic Document Feeder(left aligned,Duplex)'
color_mode='24bit Color[Fast]'
device="brother5:bus4;dev3" bw_mode='Black & White'
grayscale_mode='True Gray'
valid_resolutions=("100" "150" "200" "300" "400" "600" "1200") valid_resolutions=("100" "150" "200" "300" "400" "600" "1200")
# default options for scanning
sides=$simplex_source
mode='c'
resolution='300'
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() {
while getopts "dr:" flag; do usage() {
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"
source=$duplex_source sides=$duplex_source
;; ;;
r) r)
echo "Resolution=$OPTARG"
if [[ ! " ${valid_resolutions[*]} " =~ [[:space:]]${OPTARG}[[:space:]] ]]; then if [[ ! " ${valid_resolutions[*]} " =~ [[:space:]]${OPTARG}[[:space:]] ]]; then
echo "Resolution not supported" echo "Resolution '$OPTARG' not supported!"
echo "Supported resolutions: $(printf %s "${valid_resolutions[*]}")"
exit 1 exit 1
fi fi
resolution=$OPTARG
;; ;;
b) c)
echo "Black and white"; mode=$OPTARG
;; ;;
*) *)
;; ;;
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)
if [ "$2" = "duplex" ]; then rm "$current_pageno"
true ;;
fi dispatch)
# 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"