From e66c6da38d73f2e9b4c5a0d4f33d95d9569d60f1 Mon Sep 17 00:00:00 2001 From: Justin Yao Du Date: Sun, 8 Aug 2021 14:28:16 -0700 Subject: [PATCH] Add option to refresh devices before scanning --- iscanimage | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/iscanimage b/iscanimage index 8de07c9..9c45268 100755 --- a/iscanimage +++ b/iscanimage @@ -1,16 +1,17 @@ #!/bin/bash name='iscanimage' -version='1.0.0' +version='1.1.0' version_msg="${name} ${version} Copyright (C) 2021 Justin Yao Du. Licensed under the MIT License. https://github.com/justinyaodu/${name}" -selected_device='' output_dir='' output_format='png' +selected_device='' +refresh_devices=0 run_before='' run_after='' colorize='' @@ -27,10 +28,12 @@ Options: -f, --format FORMAT use FORMAT as the output file format and file extension (default: ${output_format}) -d, --device-name DEVICE scan from DEVICE (if unspecified, ask the user) + -r, --refresh-devices refresh all devices before scanning each file, which + might fix errors like 'open of device ... failed' -B, --before CMD evaluate CMD before scanning each file -A, --after CMD evaluate CMD after successfully scanning each file - --color always colorize output - --no-color never colorize output + --color always colorize command line output + --no-color never colorize command line output -v, --verbose show more verbose output -h, --help show this help message --version show version information @@ -116,6 +119,11 @@ scan_loop() { eval "${run_before}" fi + if (( refresh_devices )); then + echoy "Refreshing devices..." + scanimage --list-devices > /dev/null + fi + local scan_cmd=(scanimage \ --device-name "${selected_device}" \ --format "${output_format}" \ @@ -190,6 +198,9 @@ parse_options() { load_devices exit 0 ;; + -r|--refresh-devices) + refresh_devices=1 + ;; --color) colorize=1 ;;