If your document has, for example, a page "1" and page "A1", the page name property will be "1" for both pages. The script would create a PDF of page 1 twice, overwriting the first PDF on the second pass. You'll need to include a check to as to whether the section prefix of the applied section property is an empty string—if not, then include the section prefix when concatenating the desired PDF file name. The other issue is setting the page range of the PDF export preferences with the name of the page. I don't have time to test it right now, but one way to work around that is to use the document offset property, which is similar to absolute page numbering, instead of the page name property.
I'm not much into AppleScript so I cannot give code samples.
David outlined some problems with your approach.
There is another detail, a case where PDFs can be overwritten because of page naming:
Prefix or not: Two or more pages that share the same name in different sections.
What's not clear for me:
What would you like to get as desired output if a document has the following page names where are two sections and section two is prefixed with "A" for e.g. "Appendix".
Should it be:
220.pdf , 221.pdf , 222.pdf, 223.pdf, 224A1.pdf, 225A2.pdf, 226A3.pdf ?
or something else?
Then you could do two things:
1. Set the naming of the pages so that the prefixes are added to the page names.
That would lead to names I suggested with my little example above.
In ExtendScript code this would be:
app.activeDocument.sections.everyItem().includeSectionPrefix = true;
This is doable in AppleScript as well.
EDIT: Also doable in the UI, but not in one go like the script line above.
2. But one problem remains: If two sections share the same page names—and/or the same prefixes—still files will be overwritten.
Maybe a rare case, because every InDesign user is given a fair warning if trying to set up sections like that, but who knows:
The user can deny the warning or turn off warnings with that "Don't show again" checkbox so that InDesign will give no warning at all.
So you need a control system if a document page has the same name like a different one in the same document.
A third item added:
3. Make sure that the files you want to write do not already exist.
You could check this before writing any file to disk.