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.


  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.

2 Answers 2


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


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
    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"

The reason you're running into unexpected "file already exists" errors is that the Make Sequential action only works for single iterations of the workflow. If you run the workflow twice, it will fail the second time, because the counter resets and it tries to start the numbering at 1. So if you already have an item named Scan 2013-01-07 01.pdf, it tries to make another named that and fails.

The workaround is to use a script to do the renaming for you, which can detect if there are already duplicate files and start over.

In place of the Make Sequential action, add a Run Shell Script action, with the shell set to /usr/bin/python, the input to as arguments, and paste in this script:


import sys
import os

decimalPadding = 2 # pad to x decimal places
returnFiles = ''

for filePath in sys.argv[1:]:
    pathNoExt, extension = os.path.splitext(filePath)
    counter = 1
    newPath = pathNoExt + ' %0*d' % (decimalPadding, counter) + extension

    #     Increment counter until we find a file that does not exist
    while os.path.exists(newPath):
        counter += 1
        newPath = pathNoExt + ' %0*d' % (decimalPadding, counter) + extension
    os.rename(filePath, newPath)
    returnFiles += newPath + '\n'

print returnFiles #pass the renamed files for other automator actions

That should get you the results you desire.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .