Automator Print Plugin: Append Output to Existing PDF File

automatorpdfpluginsprinting

I would like to create a Print Plugin to append the output to an existing PDF File.

Here are my steps so far:

  • Ask for Finder Items
  • Combine PDF Pages (append)
  • Open Finder Items

It sort of does the job, but:

  • It prepends the output: the new output is inserted at the beginning rather than the end.
  • I creates a new file.

I can handle the new file situation, I suppose, by doing a Save As…, but I don’t want the new output to be placed at the beginning.

How can I append the output at the end of an existing PDF file?

Best Answer

A very old discussion on https://discussions.apple.com/thread/2240963 had the solution.

Here is a working version of the plugin:

1   Ask for Finder Items
        Type: Files
2   Set Value of Variable
        Variable: original
3   Run Shell Script
        Pass input: as arguments
        Script: echo $2
                echo $1
4   Combine PDF Pages
        Combine documents by: Appending pages
5   Get Value of Variable
        Variable: original
6   Run Shell Script
        Pass input: as arguments
        Script: mv $1 $3
7   Open Finder Items
        Open with: Default Application

Step 3 solves the problem of appending rather than prepending the file by echoing the items in the reverse order. Steps 2, 5 & 6 takes care of creating a new file by renaming (and moving) the new file to the original.

As soon as I have tested it out more, I will post a link to a working version.