MacOS 12.3 (Monterey) Automator Combine PDF Pages breaks workflows

I have a few workflows that have stopped working because when the "Combine PDF Pages" action runs, it fails.


I get the error "The action “Combine PDF Pages” encountered an error: “The operation couldn’t be completed. Command line tool returned error 127.: 127”


If anyone has any ideas or how to fix this I would be very appreciative.


Thanks in advance.


Brandon

MacBook Pro 13″, macOS 12.3

Posted on Mar 22, 2022 7:09 AM

Reply
Question marked as Top-ranking reply

Posted on Mar 22, 2022 9:04 AM

The following AppleScript will allow you to select n-tuple PDFs from a file chooser, and then merge them in selection order to a user-designated output pdf (in this case ~/Desktop/merged.pdf). With little effort, this AppleScript can be adopted for use in a Run AppleScript action in an Automator Application, Quick Action, or Shortcut.


Copy and paste into Apple's Script Editor, compile, and run to test. Does not change any existing PDF.


(*
  merge_pdf.applescript
  
  Prompt user for PDF filenames to merge using the ⌘-key for multiple selection.
  PDF will be merged in the order of their selection and written to an arbitrary
  PDF filename on the Desktop (in this example, merged.pdf)
  
  Tested: macOS 11.4, 11.6.5, 12.3
  VikingOSX, 2021-06-24, Apple Support Communities, No warranty/support implied.
*)

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

property NSString : a reference to current application's NSString
property NSURL : a reference to current application's NSURL
property PDFDocument : a reference to current application's PDFDocument

# tilde path to absolute path
set merged_pdf to (NSString's stringWithString:"~/Desktop/merged.pdf")'s stringByStandardizingPath()

set msg to "Select multiple PDF using the ⌘-key in the order of your merge preference."
set pdfList to (choose file with prompt msg of type {"com.adobe.pdf"} default location (path to desktop) with multiple selections allowed)

set outurl to NSURL's fileURLWithPath:(POSIX path of (item 1 of pdfList))
set outpdf to PDFDocument's alloc()'s initWithURL:outurl
set pdfList to rest of pdfList
set lastPage to outpdf's pageCount()

repeat with pdfdoc in pdfList
	set thisURL to (NSURL's fileURLWithPath:((POSIX path of pdfdoc) as text))
	set thisPDF to (PDFDocument's alloc()'s initWithURL:thisURL)
	
	# PDF pages are zero-based
	repeat with n from 1 to thisPDF's pageCount()
		set this_page to (thisPDF's pageAtIndex:(n - 1))
		(outpdf's insertPage:this_page atIndex:lastPage)
		set lastPage to outpdf's pageCount()
	end repeat
end repeat
outpdf's writeToFile:merged_pdf
return


I also have this written in Swift for those that want a compiled tool.

Similar questions

39 replies

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

MacOS 12.3 (Monterey) Automator Combine PDF Pages breaks workflows

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.