#!/usr/bin/env bash # author: Daniel Sommer # license: MIT name="$1" directory="$2" [[ -z "$directory" ]] && directory="$(mktemp -d)" [[ -z "$name" ]] && name="$(date '+%Y-%m-%d_%H%M%S').png" [[ "$name" != *".png" ]] && name="$name.png" mkdir -p "$directory" [[ ! -d "$directory" ]] && printf "error: directory '"$directory"' does not exist and can not be created!\n" >&2 && exit 1 output="$directory/$name" scanimage --format="png" --output-file "$output" --resolution "300" --mode "Color" 2> /dev/null [[ ! -e "$output" ]] && printf "error: no document was scanned!\n" >&2 && exit 1 if [[ "$(du "$output" | awk '{print $1}')" == "0" ]]; then printf "error: scanned document '"$output"' is empty!\n" >&2 rm -rf "$output" exit 1 fi printf "$output\n"