use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "Quartz" -- required for PDF stuff
set inPath to POSIX path of (choose file with prompt "Choose a PDF file:")
set folderPath to POSIX path of (choose folder with prompt "Choose a folder to save the separated pages to.")
its splitPagesInPath:inPath savingInFolder:folderPath
on splitPagesInPath:inPath savingInFolder:folderPath
-- make URL of the PDF
set inNSURL to current application's |NSURL|'s fileURLWithPath:inPath
-- get name of PDF
set docName to inNSURL's lastPathComponent()
-- make URL of output folder
set outFolderNSURL to current application's |NSURL|'s fileURLWithPath:folderPath
-- make PDF document from the file
set theDoc to current application's PDFDocument's alloc()'s initWithURL:inNSURL
-- store media bounds of page 1; unnecessary in most cases
set theBounds to (theDoc's pageAtIndex:0)'s boundsForBox:(current application's kPDFDisplayBoxMediaBox)
-- count the pages
set theCount to theDoc's pageCount() as integer
repeat with i from 1 to theCount
-- build new document's name
set newDocName to (its addString:("-" & i) beforeExtensionIn:docName)
-- make URL for new PDF
set outNSURL to (outFolderNSURL's URLByAppendingPathComponent:newDocName)
-- get page of old PDF
set thePDFPage to (theDoc's pageAtIndex:(i - 1)) -- zero-based indexes
-- set media bounds if you stored it above
(thePDFPage's setBounds:theBounds forBox:(current application's kPDFDisplayBoxMediaBox))
-- make new PDF document
set theNewPDFDocument to current application's PDFDocument's new()
-- insert the page
(theNewPDFDocument's insertPage:thePDFPage atIndex:0)
-- save the new PDF
(theNewPDFDocument's writeToURL:outNSURL)
end repeat
end splitPagesInPath:savingInFolder:
on addString:extraString beforeExtensionIn:aPath
set aString to current application's NSString's stringWithString:aPath
set newString to current application's NSString's stringWithFormat_("%@%@.%@", aString's stringByDeletingPathExtension(), extraString, aString's pathExtension())
return newString as text
end addString:beforeExtensionIn:
Anyway, I had this problem for ages, ppl asking me to crack their documents. I was coding this below. Relies on Ghostscript, that can be installed from brew.
I guess you can mix mine with his, and get the three name nomenclature working. btw I am sorry about the “pasta mix coding”, I am new to this.