Here is simple ASObjC Script that do follow:
Choose a PDF file of multiply pages, swap page with pageAtIndex:indexNumber
with a single page PDF. In other words page 5 of choose file (PDF) will swap with singlePageDoc.pdf
It works, but I wonder could this be done in more simple way ??
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "Quartz"
use scripting additions
set thePath to POSIX path of (choose file)
set theURL to current application's |NSURL|'s fileURLWithPath:thePath
set savePath to POSIX path of (path to desktop) & "newSavedFile.pdf"
set saveFile to current application's |NSURL|'s fileURLWithPath:savePath
set insertPath to POSIX path of (path to desktop) & "singlePageDoc.pdf"
set insertURL to current application's |NSURL|'s fileURLWithPath:insertPath
my swapPageWith:theURL insertPage:insertURL pageAtIndex:5 savePath:saveFile
on swapPageWith:theURL insertPage:insertURL pageAtIndex:indexNumber savePath:saveFile
set pdfDoc to current application's PDFDocument's alloc()'s initWithURL:theURL
set insertPage to current application's PDFDocument's alloc()'s initWithURL:insertURL
set pageCount to pdfDoc's pageCount()
if indexNumber is greater than pageCount then return
try
if (pdfDoc is not missing value) then
(pdfDoc's insertPage:(insertPage's pageAtIndex:0) atIndex:(indexNumber - 1))
(pdfDoc's removePageAtIndex:indexNumber)
(pdfDoc's writeToURL:saveFile)
end if
end try
end swapPageWith:insertPage:pageAtIndex:savePath: