scanimage(1) command python wrapper

To reduce clutter and improve the efficiency of my home-office, I like to digitize all my “important” documents. To accomplish this task, I use a HP All-in-one scanner, an open sourced document management software called KnowledgeTree, and scanimage(1) from the SANE project.


For the longest time, I was very happy with my simple bash script to store my command options to scanimage(1) and I would “manually” set any arguments (e.g. number of pages). This worked pretty well for single sided documents. After some time, I finally had it with the headache of modifying the command options manually when I wanted to scan double side documents and decided to write a python script that would wrap all this knowledge into a script. I call my script It has very simple usage: [-d | –double] total-pages

The script does three things. First, it manages the “–batch-count” and “–batch-start” command line options depending upon the parameters of the scan job. Also, it automatically calculates the number of pages that are to be scanned for a two-pass double sided scan job. It is only required to specify the ‘-d’ flag and the total number of pages, both front and back, that are to be scanned. Lastly, the script will use the convert(1) command to trim any whitespace contained in the image that is not part of the original document.
