Merging pdfs with automator

automatormergepdfrename

I'm scanning my mail and end up with two versions: front & back.

Files are named: scanf 01.pdf & scanb 01.pdf

I'm scanning about 40 pages a day, so it ends up to quite some lists.

Now, with automator, I've done the following:

  1. Get Selected Finder Items # "scanf 01.pdf" & "scanb 01.pdf"
  2. Combine PDF Pages
  3. Move Finder Items # to Desktop
  4. Name Single Item # so that its not a random name, but "Scan.pdf"
  5. Add Date or Time # "Scan 2013-01-07.pdf"
  6. Make Sequential # "Scan 2013-01-07 01.pdf" (is at least the idea)
  7. Label Finder Items # Adds a red label, so I didnt see it yet

Step 6 is not working, as the sequence starts over every time I select two new files. So it says 'name already exists', after that it stops.

Questions:

  1. How can I make step 6 work?
  2. Is there something that automatically merges files, so that Scanf 01.pdf is merged with Scanb 01.pdf and that Scanf 02.pdf is merged with Scanb 02.pdf, and so on. As my current automator setup requires me to select the two files.

Best Answer

I didn't really test this, but you could use a shell script instead.

#!/bin/bash

join="/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py"
date=$(date '+%Y-%m-%d')
last=$(ls ~/Desktop/$date*.pdf 2> /dev/null | tail -n1 | sed -E 's/.* 0*(.*)\.pdf$/\1/g' || 0)

cd ~/Documents/Scanned/
for f in scanf*.pdf; do
    ((last++))
    output="$HOME/Desktop/$date $(printf %03d $last).pdf"
    python "$join" -o "$output" "$f" "${f/scanf/scanb}"
    osascript -e 'on run {f}
tell app "Finder" to set label index of (posix file f as alias) to 2
end' "$output"
done