I have this working in an Automator workflow. Here is the action flow:
- Ask for Finder Items
- Start at: Desktop
- Type: Files and Multiple selection is selected.
- Note 1: Chose not to use Get Selected Finder Items as unreliable.
- Note 2: The order of selected PDF files should be the order within the combined PDF
- Run AppleScript
- This makes a list from the Ask for Finder Items PDF selection.
- Copies the PDF filename list to the clipboard as this will be used later in the original file moving process.
- Prompt user with a list from which to choose the combined PDF filename
- Prompt user for the folder to move the original PDF too.
- Set two preexistent Automator variables and set these with the combined PDF name string, and the destination folder respectively.
- combined_pdf
- PDF_Delete_Candidates
- Passes the original PDF selections through to the next action.
- Combine PDF Pages
- Get Value of Variable - combined_pdf
- Run Shell Script
- Pass Input : Arguments
- The temporary location of the combined PDF
- The stored value of the combined PDF filename in the combined_pdf variable
- Simple Bash move (mv) statement to rename the temporary combined PDF to the name stored in the combined_pdf Automator variable.
- Get Value of Variable - PDF_Delete_Candidates
- Run AppleScript
- Get the value of the passed in folder name
- Perform a Finder repeat loop moving the original filenames from the stored clipboard list into the folder path stored in the Automator variable.
After you set up the actions in your workflow, at the bottom of the workflow, you will see two icons.
Click the rightmost symbol, and you will see an empty area with the heading Variables. Right-click in this empty area, and choose New Variable from the secondary menu. You will want to do this twice. Just give them the following names, and leave the Value field alone:
- combined_pdf
- PDF_Delete_Candidates
Here is the contents of item 2 above (Run AppleScript). Just copy and replace the content of your Run AppleScript action. The choose statements are long and wrap. The last set value of variable statement wraps.
property aDesktop : (path to desktop)
on run {input, parameters}
set {TID, AppleScript'stext item delimiters} to {AppleScript'stext item delimiters, ","}
set seLst to text items of (input as text)
set the clipboard toseLst
set AppleScript'stext item delimiters to TID
set thePDF to (choose from listseLstwith title "Combined PDF Path and Name" with prompt "Pick Combined PDF Output Name:" default itemsnone without multiple selections allowed and empty selection allowed)
if the result is false then error -128
set destination_folder to (choose folderwith prompt "Folder to receive original files after PDF combine:" default locationaDesktop without invisibles, multiple selections allowed and showing package contents)
set {TID, AppleScript'stext item delimiters} to {AppleScript'stext item delimiters, "."}
set path_ext to text items of (thePDF as text)
set AppleScript'stext item delimiters to TID
-- the Automator workflow variables must exist beforehand as part of the workflow setup
set value of variable "PDF_Delete_Candidates" of front workflow to destination_folder
set value of variable "combined_pdf" of front workflow to POSIX path of ((item 1 of path_ext) & "_combined." & "pdf") as text
return input
end run
Here is the content of item 5 (Run Shell Script). Just copy and replace the boilerplate content of your Run Shell Script action:
# move and rename the combined PDF file from its temporary folder location to the
# original path stored in the Automator variable "combined_pdf".
mv "$1" "$2"
And finally, the contents of item 7 (Run AppleScript) that moves your original files to the designated folder. Again, copy and paste this to replace the boilerplate Run AppleScript content.
-- get the list of original selected PDF items from the clipboard and
-- move them into the designated folder for subsequent manual deletion
on run argv
if length of argv = 0 then return
set move_folder to (item 1 of argv) as text
tell application "Finder"
repeat with anItem in (get the clipboard as list)
moveitem (anItem as alias) tomove_folder with replacing
end repeat
end tell
return
end run