Skip to content

Instantly share code, notes, and snippets.

@alistairstead3408
Created December 10, 2013 17:22
Show Gist options
  • Save alistairstead3408/7894429 to your computer and use it in GitHub Desktop.
Save alistairstead3408/7894429 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# This script traverses through a directory of pdf's scanned in Windows with default scanned names
# e.g. Image.jpg, Image (1).jpg etc
# It merges them in ascending order and outputs them in ./pdfs/
for i in $(find . -name "*" -type d);
do
STR=$i
NAME=${STR:2:${#STR}}
#only target folders with length > 2
if [ "${#NAME}" -gt "2" ]; then
IMAGEPRE="$(pwd)/"$NAME
#only check 1-4
for f in $(seq 1 4);
do
if [ "$f" -eq "1" ];
then
IMAGEPOST="Image.jpg"
else
IMAGEPOST="Image ($f).jpg"
fi
convert "$NAME/$IMAGEPOST" "$NAME/$f.pdf"
done
ARGS=""
for g in $(seq 1 4);
do
if [ ! -f $NAME/$g".pdf" ]; then
echo "" #$NAME/$g".pdf does not exist!"
else
ARGS=$ARGS" $NAME/$g.pdf"
fi
done
echo $ARGS
"/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py" -o pdfs/$NAME.pdf $ARGS
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment