Here’s how to create a combined workflow in Mac Automator that first converts .pages
documents to PDF, then merges the resulting PDFs into a single PDF file.
Steps to Create a Combined Workflow in Automator
First, brew install poppler
Next, Open Automator:
- Open the Automator app and create a new Quick Action.
Set the Input Type:
- Set the Workflow receives current option to files or folders in Finder.
Add “Run AppleScript” to Convert .pages
Files to PDF:
- Add a Run AppleScript action.
- Paste the following AppleScript to convert each
.pages
document to a PDF.
on run {input, parameters}
set exportFolder to (choose folder with prompt "Select folder to save exported PDFs")
set pdfFiles to {}
tell application "Pages"
activate
repeat with filePath in input
open filePath
delay 1 -- Wait for the document to open
set docName to name of front document
set exportPath to ((exportFolder as text) & docName & ".pdf") as «class furl»
export front document to exportPath as PDF
close front document saving no
-- Store the PDF path in the list
set end of pdfFiles to (POSIX path of exportPath)
end repeat
end tell
return pdfFiles -- Return the list of PDF paths for the next step
end run
This code exports each .pages
document as a PDF in a chosen folder and collects their paths for the next step.
Add “Run AppleScript” to Combine the PDFs:
- Add another Run AppleScript action.
- This AppleScript will use
pdfunite
to merge the PDFs created in the previous step:applescript
on run {input, parameters}
-- Choose save location for the combined PDF
set outputFile to choose file name with prompt "Save combined PDF as:" default name "CombinedDocument.pdf"
set outputPath to POSIX path of outputFile
-- Collect POSIX paths of all PDF files from the previous step
set pdfPaths to ""
repeat with pdfFile in input
set pdfPaths to pdfPaths & quoted form of pdfFile & " "
end repeat
-- Use full path to pdfunite
do shell script "/opt/homebrew/bin/pdfunite " & pdfPaths & quoted form of outputPath
display dialog "PDFs combined successfully!" buttons {"OK"} default button "OK"
return outputFile
end run
- This code takes the list of PDF paths, combines them with
pdfunite
, and saves the final PDF in the specified location.
Save the Quick Action:
- Save the Quick Action with a descriptive name, like Convert and Combine Pages to PDF.
Running the Workflow
- Select multiple
.pages
files in Finder. - Right-click, go to Quick Actions, and select your newly created Convert and Combine Pages to PDF.
- Choose the folder to save the intermediate PDFs, then select a location and filename for the final combined PDF.
This workflow should now convert .pages
documents to PDFs and combine them into one.
0 Comments