Scripts for scanning There is an interview with Friedrich Duerrenmatt where he calls the photocopier the greatest invention ever. It allows him to cut up manuscripts, glue the pieces together, and then copy them for more cutting and gluing. I have seen the benefit of writing by hand too. I like to write answers to exercises by hand on blank pages and then scan them to PDF files. I would scan a 3-page A5 document like so: $ jscan a5 $ jscan a5 $ jscan a5 $ jpdf a5 $ ls 01.jpg 02.jpg 03.jpg out.pdf I have bundled the scripts here using a script like the one shown in "The UNIX Programming Environment" by Brian Kernighan and Rob Pike. To unbundle them into your current directory (overwrites!), run cat 2023-334.txt | sed -n '/^# sh from here to unbundle$/,$p' | sh You don't even need to save a copy of this file. At the time of writing, you can replace "cat 2023-334.txt" with any of the following two: curl https://dkalak.de/feed/2023-334.txt echo /feed/2023-334.txt | nc dkalak.de 70 # sh from here to unbundle echo jscan 1>&2 cat >jscan <<'End of jscan' #!/bin/sh # jscan: scan a page to jpeg case $# in 1|2) ;; * ) echo 'Usage: jscan format [file[.jpg]]' 1>&2; exit 1 esac case $1 in a4 ) x=210; y=297 ;; a5 ) x=148; y=210 ;; a5l) x=210; y=148 ;; a6 ) x=105; y=148 ;; a6l) x=148; y=105 ;; * ) echo 'Bad page format, pick a4 a5[l] a6[l]' 1>&2; exit 1 esac case $2 in '' ) for i in `seq -w 99`; do [ -f $i.jpg ] || break; done file=$i.jpg ;; *.jpg) file=$2 ;; * ) file=$2.jpg ;; esac device=$(scanimage -L | grep -m1 Samsung | cut -d' ' -f2 | tr -d \`\') case $device in '') echo 'No device found' 1>&2; exit 1 esac scanimage --format=jpeg --resolution 300 --mode=Color \ -d $device -x $x -y $y >$file End of jscan echo jpdf 1>&2 cat >jpdf <<'End of jpdf' #!/bin/sh # jpdf: convert jpeg files to pdf case $# in 1|2) ;; * ) echo 'Usage: jpdf format [out[.pdf]]' 1>&2; exit 1 esac case $1 in a4|a5|a6) format=$1 ;; *) echo 'Bad page format, pick a4 a5 a6' 1>&2; exit 1 esac case $2 in '' ) file=out.pdf ;; *.pdf) file=$1 ;; * ) file=$1.pdf ;; esac convert -density 72 -page $format *.jpg $file End of jpdf exit Written by Daniel Kalak in 2023. Verbatim copying and distribution of this entire article are permitted worldwide, without royalty, in any medium, provided this notice is preserved. Copying and distribution of the given shell scripts, with or without modification, are permitted worldwide, without royalty, in any medium. This file is offered as-is, without any warranty. EOF