From a786b9ef32cb0eca27b5a5fbc22d697e4e9e0bed Mon Sep 17 00:00:00 2001 From: Prunebutt Date: Sun, 21 Sep 2025 22:38:29 +0200 Subject: [PATCH 1/4] add more options to scanning --- .gitignore | 1 + scanbuddy.bash | 61 ++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a136337 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pdf diff --git a/scanbuddy.bash b/scanbuddy.bash index ca61674..efd16f5 100755 --- a/scanbuddy.bash +++ b/scanbuddy.bash @@ -1,15 +1,23 @@ #!/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:bus2;dev2" +# device=$(scanimage -f "%d%n" | grep brother5 | head -n 1) +echo "Selecting scanner '$device'" -device="brother5:bus4;dev3" +# 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' + current_page=$(find "$PWD" -name "out*.pdf" | sort | tail -n 1); read -r current_pageno <<<"${current_page//[^0-9]/ }" @@ -18,26 +26,55 @@ current_pageno=${current_pageno:-0} next_out_file="out$((current_pageno+1)).pdf" scan() { - while getopts "dr:" flag; do + usage() { + echo "scanbuddy.bash scan -d -r -b " + } + + while getopts "dr:c:" flag; do case ${flag} in d) echo "Scanning duplex" - source=$duplex_source + sides=$duplex_source ;; r) - echo "Resolution=$OPTARG" 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 fi + resolution=$OPTARG ;; - b) - echo "Black and white"; + c) + mode=$OPTARG ;; *) ;; esac 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'..." + echo scanimage \ + --device-name=$device \ + --format=pdf \ + --output-file="$next_out_file" \ + --mode="$scanner_mode" \ + --resolution="$resolution" \ + --source="$sides" } case "$1" in From d7a31148939441834cf862e9f4c67ec7b81afa5e Mon Sep 17 00:00:00 2001 From: Prunebutt Date: Sun, 21 Sep 2025 22:39:47 +0200 Subject: [PATCH 2/4] cleanup code --- scanbuddy.bash | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/scanbuddy.bash b/scanbuddy.bash index efd16f5..6893419 100755 --- a/scanbuddy.bash +++ b/scanbuddy.bash @@ -10,7 +10,6 @@ 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 @@ -18,11 +17,10 @@ sides=$simplex_source mode='c' resolution='300' + 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() { @@ -80,17 +78,6 @@ scan() { case "$1" in scan) scan "${@:2}" - exit 0 - - if [ "$2" = "duplex" ]; then - true - fi - - # cat < Date: Mon, 22 Sep 2025 00:22:42 +0200 Subject: [PATCH 3/4] add geometry --- scanbuddy.bash | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scanbuddy.bash b/scanbuddy.bash index 6893419..6c088b3 100755 --- a/scanbuddy.bash +++ b/scanbuddy.bash @@ -1,7 +1,7 @@ #!/usr/bin/env bash -device="brother5:bus2;dev2" -# device=$(scanimage -f "%d%n" | grep brother5 | head -n 1) +# device="brother5:bus2;dev2" +device=$(scanimage -f "%d%n" | grep brother5 | head -n 1) echo "Selecting scanner '$device'" # option values for the brother DS-740D scanner @@ -66,13 +66,15 @@ scan() { esac echo "Scanning to '$next_out_file'..." - echo scanimage \ + scanimage \ --device-name=$device \ --format=pdf \ --output-file="$next_out_file" \ --mode="$scanner_mode" \ --resolution="$resolution" \ - --source="$sides" + --source="$sides" \ + -x 210 -y 297 # A4 + } case "$1" in From 498aba165eebf9e1fea0c1ef62f5b5de0c94fa5a Mon Sep 17 00:00:00 2001 From: Prunebutt Date: Mon, 22 Sep 2025 12:02:44 +0200 Subject: [PATCH 4/4] add unscan and dispatch command --- scanbuddy.bash | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scanbuddy.bash b/scanbuddy.bash index 6c088b3..06565ab 100755 --- a/scanbuddy.bash +++ b/scanbuddy.bash @@ -21,6 +21,7 @@ resolution='300' current_page=$(find "$PWD" -name "out*.pdf" | sort | tail -n 1); read -r current_pageno <<<"${current_page//[^0-9]/ }" current_pageno=${current_pageno:-0} +last_out_file="out$current_pageno.pdf" next_out_file="out$((current_pageno+1)).pdf" scan() { @@ -74,13 +75,17 @@ scan() { --resolution="$resolution" \ --source="$sides" \ -x 210 -y 297 # A4 - } case "$1" in scan) scan "${@:2}" ;; + unscan) + rm "$current_pageno" + ;; + dispatch) + ;; *) echo "Usage: scanbuddy" ;;