#!/bin/bash

# Quick and dirty script to collect last n scanned images from magic
# wand scanner to pdf.

[ -z "$1" ] && echo "usage: $0 <outfile> [<nb pages>]" && exit 1

OUTFILE="$1"

if [ -z "$2" ]; then
    COUNT=1
else
    COUNT=$2
fi
echo combining last $COUNT images
ROOT=/vol/magicwand
MEDIA=$ROOT/DCIM/101MEDIA
mount $ROOT
IMGS=$(ls $MEDIA/*.JPG | tail -n $COUNT)
for i in $IMGS; do echo $i; done
convert $IMGS $OUTFILE
echo into:
ls -l $OUTFILE
umount $ROOT

