-
-
Save anonymous/bc52bca235a1fd830b6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set +o noclobber | |
timestamp=$(date +%Y%m%d%H%M%S) | |
device="$1" | |
resolution=300 | |
mode='Black & White' | |
format=tiff | |
batch="$timestamp"_%03d.tiff | |
sleep 0.01 | |
# if [ "$(which usleep 2>/dev/null )" != '' ];then | |
# usleep 10000 | |
# else | |
# sleep 0.01 | |
# fi | |
# From: https://github.com/rtomayko/shocco/blob/master/shocco.sh#L108 | |
# Work and Cleanup | |
# ---------------- | |
# Make sure we have a `TMPDIR` set. The `:=` parameter expansion assigns | |
# the value if `TMPDIR` is unset or null. | |
: ${TMPDIR:=/tmp} | |
# Create a temporary directory for doing work. Use `mktemp(1)` if | |
# available; but, since `mktemp(1)` is not POSIX specified, fallback on naive | |
# (and insecure) temp dir generation using the program's basename and pid. | |
: ${WORK:=$( | |
if command -v mktemp 1>/dev/null 2>&1 | |
then | |
mktemp -d "$TMPDIR/$(basename $0).XXXXXXXXXX" | |
else | |
dir="$TMPDIR/$(basename $0).$$" | |
mkdir "$dir" | |
echo "$dir" | |
fi | |
)} | |
# We want to be absolutely sure we're not going to do something stupid like | |
# use `.` or `/` as a work dir. Better safe than sorry. | |
test -z "$WORK" -o "$WORK" = '/' && { | |
echo "$(basename $0): could not create a temp work dir." | |
exit 1 | |
} | |
# We're about to create a ton of shit under our `$WORK` directory. Register | |
# an `EXIT` trap that cleans everything up. This guarantees we don't leave | |
# anything hanging around unless we're killed with a `SIGKILL`. | |
trap "rm -rf $WORK" 0 | |
# Change into the work directory. The program will finish up in there. | |
cd "$WORK" | |
# Scanning | |
scanimage --device-name "$device" --resolution "$resolution" --mode "$mode" --format "$format" --batch="$batch" | |
# Merging scanned tiff files | |
tiffcp "$WORK"/*.tiff "$WORK"/output.tiff | |
# Convert tiff to pdf | |
tiff2pdf -o /home/me/scan_docs/"$timestamp".pdf "$WORK"/output.tiff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment