.dots/scripts/scan/batch-scan.sh
2024-11-05 15:44:12 +01:00

39 lines
1 KiB
Bash
Executable file

#!/usr/bin/env bash
# author: Daniel Sommer <daniel.sommer@velvettear.de>
# license: MIT
trap 'printf "\n>> batch scan aborted after $SECONDS seconds!\n" && exit 0' SIGINT
directory="$1"
tmp="$(mktemp -d)"
[[ -z "$directory" ]] && directory="$tmp"
mkdir -p "$directory"
[[ ! -d "$directory" ]] && printf "error: directory '"$directory"' does not exist and can not be created!\n" >&2 && exit 1
printf ">> batch scan started...\n"
postprocess() {
ocr="$(/home/velvettear/.dots/scripts/ocr.sh "$file")"
printf "> #"$3": ocr for file '"$file"' finished!\n"
printf "$ocr" > "$file.ocr"
if [[ "$directory" != "$tmp" ]]; then
mv "$file" "$directory"
mv "$file.ocr" "$directory"
fi
}
counter=1
while true; do
sleep 1
file="$tmp/$(date '+%Y-%m-%d_%H%M%S.png')"
scanimage --format="png" --output-file "$file" --resolution "300" --mode "Color" 2> /dev/null
if [[ "$?" != "0" ]]; then
rm -rf "$file" 2> /dev/null
continue
fi
printf "> #"$counter": scanning to '"$file"' finished!\n"
#postprocess "$file" "$directory" "$counter"
((counter++))
done