Skip to content

Instantly share code, notes, and snippets.

@InsOpDe
Created April 1, 2019 18:36
Show Gist options
  • Save InsOpDe/6a4f2404f9de2b6401f99bc9439004e7 to your computer and use it in GitHub Desktop.
Save InsOpDe/6a4f2404f9de2b6401f99bc9439004e7 to your computer and use it in GitHub Desktop.
Script for brscan-skey
#! /bin/sh
set +o noclobber
#
# $1 = scanner device
# $2 = friendly name
#
# ==============================================
# resolution: dpi
# mode: color, grayscale and so on
# open_filemanager: open file manager after print job
# output_dir: where to output
# ==============================================
resolution=300
device=$1
mode="24bit Color"
open_filemanager="true"
output_dir=~/brscan
tmp_dir="$output_dir/tmp_dir"
mkdir -p "$tmp_dir"
if [ "`which usleep 2>/dev/null `" != '' ];then
usleep 100000
else
sleep 0.1
fi
output_file="$output_dir"/"`date +%H-%M-%S`"
# ==============================================
# Scan everything and store in $tmp_dir
# ==============================================
scanimage --device-name "$device" --format=tiff --mode "$mode" --resolution $resolution --batch="$tmp_dir/tmp-image%02d" --batch-start=0 --batch-increment=1
# ==============================================
# Convert everything to pdf and make a compressed copy of them
# ==============================================
counter=0
for image in $tmp_dir/tmp-image*
do
filename="$output_file""_""$counter.pdf"
filenamesmall="$output_file""_small_""$counter.pdf"
tiff2pdf -x$resolution -y$resolution -o"$filename" "$image"
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile="$filenamesmall" "$filename"
chmod 666 "$filename"
chmod 666 "$filenamesmall"
rm $image
counter=$((counter+1))
done
rm -r $tmp_dir
# ==============================================
# Starting File Manager if requested
# ==============================================
if $open_filemanager = "true";then
if [ "`which nautilus`" != '' ];then
nautilus $output_dir
elif [ "`which konqueror`" != '' ];then
konqueror $output_dir
elif [ "`which d3lphin`" != '' ];then
d3lphin $output_dir
fi
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment