I just copied and pasted the two parts of the Pages to PDF AppleScript, from the linked post, into Script Editor on El Capitan 10.11.6 and saved it as an application to my Desktop. I then tested it with nine very different Pages documents, as well as these same nine documents in a folder that I also dropped on the application. Every single Pages document was correctly exported to PDF.
This script does not work correctly when Pages documents are dropped on it in macOS 11.2.3.
Here is the Pages to PDF AppleScript in two parts as before, that must be pasted into the Script Editor with a blank line between the appending:
Part 1
-- Pages2PDF.applescript
-- Drag and drop file(s), or folder(s) onto application icon to export PDF at source location
-- Requires Pages v5.6 or later thru Pages 10 (tested)
-- Tested: macOS 10.14.6, 10.15.4
-- VikingOSX, 2020-05-04, Apple Support Communities, No warranties expressed or implied
use scripting additions
property valid_kind : {"Pages Publication", "Pages document"}
property fileCnt : (0 as integer)
property app_icon : "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/MultipleItemsIcon.icns"
on open dropped_items
tell application "Pages" to set aversion to its version
considering numeric strings
if aversion < "5.6" then
display alert "You need Pages v5.6 or later to run this script" giving up after 10
quit
end if
end considering
repeat with anItem in the dropped_items
try
tell application "Finder"
set akind to kind of anItem
if akind is equal to "Folder" then
set docList to (every item in entire contents of folder anItem ¬
whose kind is in valid_kind) as alias list
repeat with afile in docList
my export_file(afile)
end repeat
else if akind is in valid_kind then
my export_file(anItem)
else
log "ignore" # not a folder or pages document
end if
end tell
on error errmsg number errnbr
set errval to "Dropped Items repeat - " & (anItem as text)
my error_handler(errval, errnbr, errmsg)
quit
end try
end repeat
if fileCnt > 0 then
display dialog "Export Complete." & return & tab & " Files exported to PDF " & " : " & (fileCnt as text) ¬
buttons {"Done"} default button "Done" with title "Pages Export Facility" with icon POSIX file app_icon as alias
else
display dialog "Export completed without any files processed." & return & "Only Pages (.pages) documents are exported to PDF." buttons {"Done"} default button "Done" with title "Pages Export Facility" with icon POSIX file app_icon as alias
end if
quit
end open