Add manuscan script

This additionally leads to `$HOME/.bin` being created via dotfiles setup
rather than manually by `.bash_profile`, so that functionality is
removed.
master
Jordan Atwood 2 years ago
parent 2dea149220
commit c84a1c8cff
Signed by: nightfirecat
GPG Key ID: 615A619C2D73A6DF
  1. 3
      src/.bash_profile
  2. 57
      src/.bin/manuscan.sh

@ -7,8 +7,7 @@ if [ -f ~/.profile ]; then
fi
### environment vars
# Ensure $HOME/.bin exists, add it to PATH
mkdir -vp "$HOME/.bin"
# add $HOME/.bin to PATH (this is created via dotfiles setup)
export PATH="${PATH}:$HOME/.bin"
# some programs (pip, notably) install into ~/.local/bin, add that to PATH too

@ -0,0 +1,57 @@
#!/usr/bin/env bash
###
### Simple scanning script using `scanimage` and `gs` to scan a series of images
### from a flatbed scanner (continuing to new pages or breaking to a new
### document based on user input as needed) in lieu of access to a feeding
### scanner.
###
set -e
SCAN_OUTPUT_DIR=~/Pictures/Scans
TMP_DIR="$(mktemp -d --suffix='scans')"
while
scan_output_filename=scan_"$(date +%Y-%m-%d-%H-%M-%S)"
page_number=1
while
echo "Scanning page $page_number"
scanimage --format tiff --resolution 150 --output "$TMP_DIR/scan$(printf '%02d' "$page_number").tiff"
echo
read -r -n 1 -p "Press enter to scan page $(( page_number + 1 )), 'n' to start scanning a new document, or any other character to stop scanning: " prompt
[[ -z "$prompt" ]]
do
(( page_number++ ))
done
echo
# convert image sequence to pdf
convert "$TMP_DIR"/*.tiff "${SCAN_OUTPUT_DIR}/${scan_output_filename}_raw.pdf"
# compress pdf
# see: https://itsfoss.com/compress-pdf-linux/
gs \
-sDEVICE=pdfwrite \
-dCompatibilityLevel=1.4 \
-dPDFSETTINGS=/prepress \
-dNOPAUSE \
-dQUIET \
-dBATCH \
-sOutputFile="${SCAN_OUTPUT_DIR}/${scan_output_filename}.pdf" \
"${SCAN_OUTPUT_DIR}/${scan_output_filename}_raw.pdf"
# remove temp files
rm -rf "${TMP_DIR:?}"/* "${SCAN_OUTPUT_DIR}/${scan_output_filename}_raw.pdf"
echo "Scanned $(( page_number )) pages to ${SCAN_OUTPUT_DIR}/${scan_output_filename}.pdf"
echo
[[ "$prompt" == 'n' || "$prompt" == 'N' ]]
do
true
done
rm -rf "$TMP_DIR"
Loading…
Cancel
Save