Four years ago, the hosting software had a tendency to compress AppleScript commands by removing white-space and thus causing the compile error you observed. That is caused by:
on opendropped_items
which was actually posted as:
on open dropped_items
And there are several other instances in that linked code example where this syntax compression has occurred and breaks the script. I have fixed the altered syntax issues, and it is now producing a PDF from a dropped Pages document.
Here you go:
(*
Copy/paste into Script Editor, and save as Text (e.g. pages2PDF.applescript). Then,
option+Save As… and save as Application to the Desktop (pages2PDF.app). Drag and
drop one or multiple Pages documents or a folder containing Pages documents onto
the application, and the PDF will be written to the same location as the original.
Reference: https://discussions.apple.com/thread/7915966?answerId=31605574022#31605574022
Version:2.0, modified to fix hosting site command concatenation
Tested: macOS 11.2.3, Pages v10.3.9
VikingOSX, 2021-03-18, Apple Support Communities, No warranties expressed/implied.
*)
use scripting additions
property pages_kind : {"Pages Publication", "Pages Document"}
on open dropped_items
repeat with anItem in dropped_items
try
tell application "Finder" to set akind to kind of anItem
if akind contains "Folder" then
tell application "Finder"
set docList to (every item in entire contents of folder anItem whose kind is in pages_kind) as alias list
end tell
repeat with afile in docList
export_file(afile)
end repeat
else if akind is in pages_kind then
export_file(anItem)
end if
on error errmsg number errnbr
my error_handler(errnbr, errmsg)
tell application "Pages" to if it is running then quit
return
end try
end repeat
end open
return
on export_file(theFile)
tell application "Finder" to set name_ext to name extension of theFile
set exportDocument to text 1 thru ((offset of name_ext in (theFile as text)) - 1) of (theFile as text) & "pdf"
-- Permissions error fix for Sierra < 10.12.4, and Pages v6, v6.0.5
close access (open for access exportDocument)
tell application "Pages"
try
set mydoc to open theFile
with timeout of 1200 seconds
if (version of it) ≥ "5.6" then
set export_quality to (Best as constant)
export mydoc to file exportDocument as PDF with properties {image quality:export_quality}
else
export mydoc to file exportDocument as PDF
end if
end timeout
close mydoc saving no
on error errmsg number errnbr
my error_handler(errnbr, errmsg)
tell application "Pages" to if it is running then quit
return
end try
end tell
tell application "Finder"
if exists (file exportDocument as alias) is true then
set extension hidden of (file exportDocument as alias) to false
end if
end tell
return
end export_file
on error_handler(nbr, msg)
return display alert "[ " & nbr & " ] " & msg as critical giving up after 10
end error_handler