I have included below a script Shane wrote in 2015. It does exactly what I want but I wondered if it could be written as an AppleScript handler, as in the following:
on combineFiles(sourceFiles, destinationFile) -- sourceFiles is an alias list and destinatinFile is a POSIX path
-- [the ASObjC code]
end combineFiles
Shane’s script:
use scripting additions
use framework "Foundation"
use framework "Quartz" -- required for PDF stuff
set inFiles to (choose file of type {"pdf"} with prompt "Choose your PDF files:" with multiple selections allowed)
set destPosixPath to POSIX path of (choose file name default name "Combined.pdf" with prompt "Save new PDF to:")
its combineFiles:inFiles savingTo:destPosixPath
on combineFiles:inFiles savingTo:destPosixPath
-- make URL of the first PDF
set inNSURL to current application's class "NSURL"'s fileURLWithPath:(POSIX path of item 1 of inFiles)
-- make PDF document from the URL
set theDoc to current application's PDFDocument's alloc()'s initWithURL:inNSURL
-- loop through the rest
set oldDocCount to theDoc's pageCount()
set inFiles to rest of inFiles
repeat with aFile in inFiles
-- make URL of the next PDF
set inNSURL to (current application's class "NSURL"'s fileURLWithPath:(POSIX path of aFile))
-- make PDF document from the URL
set newDoc to (current application's PDFDocument's alloc()'s initWithURL:inNSURL)
-- loop through, moving pages
set newDocCount to newDoc's pageCount()
repeat with i from 1 to newDocCount
-- get page of old PDF
set thePDFPage to (newDoc's pageAtIndex:(i - 1)) -- zero-based indexes
-- insert the page
(theDoc's insertPage:thePDFPage atIndex:oldDocCount)
set oldDocCount to oldDocCount + 1
end repeat
end repeat
set outNSURL to current application's class "NSURL"'s fileURLWithPath:destPosixPath
-- save the new PDF
(theDoc's writeToURL:outNSURL)
end combineFiles:savingTo:
https://macscripter.net/viewtopic.php?id=22558
Many thanks.