You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

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 10:14 AM

As an Automator Quick Action (e.g. QA Merge PDF) where you select the PDF in the Finder in the order you want them merged, and then on the first selected PDF, you control-click (two-finger tap) to access Quick Actions > QA Merge PDF from the secondary menu. The merged PDF will be written to your Desktop as merged.pdf.



And then drag/drop the Utilities Library > Run AppleScript action below it. Select everything in that Run AppleScript window and delete it. Then copy/paste the following back into that Run AppleScript action window:


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

on run {input, parameters}
	
	# tilde path to absolute path
	set merged_pdf to (NSString's stringWithString:"~/Desktop/merged.pdf")'s stringByStandardizingPath()
	
	set outurl to NSURL's fileURLWithPath:(POSIX path of (item 1 of input))
	set outpdf to PDFDocument's alloc()'s initWithURL:outurl
	set pdfList to rest of input
	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
end run


Click the hammer icon in that Run AppleScript Action to compile this code, and then Save the Quick Action. I have used an example name for it above.

Similar questions

39 replies

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.