|
|
@@ -0,0 +1,70 @@
|
|
|
+#!/bin/env bash
|
|
|
+
|
|
|
+export GDK_BACKEND=x11
|
|
|
+export SANE_DEFAULT_DEVICE='epsonds:libusb:001:006' # Specify device to avoid startup delays and scanning slowness.
|
|
|
+
|
|
|
+function check_filename {
|
|
|
+ path=$1
|
|
|
+ folder=$(dirname "$path")
|
|
|
+ file=$(basename "$path")
|
|
|
+ extension="${file##*.}"
|
|
|
+ filename="${file%.*}"
|
|
|
+
|
|
|
+ if [[ -e "$path" ]]; then
|
|
|
+ i=2
|
|
|
+ while [[ -e "$folder/$filename-$i.$extension" ]]; do
|
|
|
+ let i++
|
|
|
+ done
|
|
|
+ filename=$filename-$i
|
|
|
+ fi
|
|
|
+ echo "$folder/$filename.$extension"
|
|
|
+}
|
|
|
+export -f check_filename # Make function available to run_scan's command substitution
|
|
|
+
|
|
|
+function run_scan {
|
|
|
+ x=210 # A4 default size
|
|
|
+ y=297
|
|
|
+
|
|
|
+ case $2a in
|
|
|
+ A5)
|
|
|
+ x=148
|
|
|
+ y=210
|
|
|
+ ;;
|
|
|
+ A5R)
|
|
|
+ x=210
|
|
|
+ y=148
|
|
|
+ ;;
|
|
|
+ esac
|
|
|
+
|
|
|
+ filename=$(check_filename $1)
|
|
|
+
|
|
|
+ echo "$5 $4 $3 $x $y $filename"
|
|
|
+
|
|
|
+ scanimage --mode=$5 --format=$4 --resolution=$3 -x $x -y $y -p --output-file=$filename | \
|
|
|
+ yad --progress --text="Scanning..." --width=300 --no-buttons --auto-close
|
|
|
+}
|
|
|
+export -f run_scan # Make function available to yad button command.
|
|
|
+
|
|
|
+function update_name {
|
|
|
+ if [[ $1 -eq 4 ]]; then
|
|
|
+ filenamecheck_filename $2
|
|
|
+ fi
|
|
|
+}
|
|
|
+
|
|
|
+# Display scan-dialog.
|
|
|
+yad --form --orient=hor --width=750 --height=250 --columns=3 \
|
|
|
+ --title="Scanning Options" \
|
|
|
+ --field="Filename:SFL" /mnt/public/scan.jpg \
|
|
|
+ --field="Paper Size:CB" A4\!A5\!A5R \
|
|
|
+ --field="Resolution (DPI):CB" 100\!^150\!300 \
|
|
|
+ --field="File format:CB" jpeg\!png\!pdf \
|
|
|
+ --field="Scan Buttons:BTN" "" \
|
|
|
+ --field="Colour:FBTN" 'bash -c "run_scan %1 %2 %3 %4 Color"' \
|
|
|
+ --field="Grayscale:FBTN" 'bash -c "run_scan %1 %2 %3 %4 Gray"' \
|
|
|
+ --field="B&W:FBTN" 'bash -c "run_scan %1 %2 %3 %4 Lineart"' \
|
|
|
+ --field="Presets:BTN" "" \
|
|
|
+ --field="Art (Colour PNG):FBTN" 'bash -c "run_scan %1 %2 %3 png Color"' \
|
|
|
+ --field="Doc (Gray PDF):FBTN" 'bash -c "run_scan %1 %2 %3 pdf Gray"' \
|
|
|
+ --field="Doc (B&W PDF):FBTN" 'bash -c "run_scan %1 %2 %3 pdf Lineart"' \
|
|
|
+ #--changed-action="@update_name" \
|
|
|
+ --button=Close:1
|