Thanks for the reply Script is out of my comfort zone.
I found this droplet
https://iworkautomation.com/pages/document-export.html
but i'm getting "incompatible items" errors with the latest pages files. Anyone savvy around to troubleshoot?
on run
set theseItems
to (
choose fileof type {"com.apple.iwork.pages.pages"} with prompt "Choose the Pages documents to export to PDF:"
with multiple selections allowed)
opentheseItems
end run
on opentheseItems
-- TRIGGERED WHEN USER DRAGS ITEMS ONTO THE DROPLET
set the filesToProcess
to {}
-- filter the dragged-on items for presentation files
repeat with i
from 1
to the count of theseItems
set thisItem
to itemi
of theseItems
if my checkForIdentifier(thisItem, {"com.apple.iwork.pages.pages"})
is true then
set the end of the filesToProcess
to thisItem
end if
end repeat
if filesToProcess
is {}
then
activate
display alert "INCOMPATIBLE ITEMS" message "None of the items were Pages documents."
else
-- process the documents
my exportToPDF(filesToProcess)
end if
end open
on exportToPDF(theseFiles)
repeat with i
from 1
to the count of theseFiles
set thisFile
to itemi
of theseFiles
set thisFilePOSIXPath
to the POSIX path
of thisFile
copy my deriveNewFilename(thisFilePOSIXPath, "pdf", "-", "")
to {targetName, targetPOSIXpath}
set targetFileReference
to targetPOSIXpath
as POSIX file
tell application "Pages"
try
activate
with timeout of 1200
seconds
openthisFile
delay 1
-- EXPORT THE DOCUMENT
with timeout of 1200
seconds
export front documenttotargetFileReferenceas
PDF
end timeout
close front documentsaving
no
end timeout
on error errorMessagenumbererrorNumber
if errorNumber
is not -128
then
display alerterrorNumbermessageerrorMessage
end if
error number -128
end try
end tell
end repeat
end exportToPDF
on checkForIdentifier(thisItem, theseTypeIdentifiers)
try
-- uses Spotlight to check for specified item type
set the queryResult
to ¬
(
do shell script "mdls -raw -name kMDItemContentType " & ¬
quoted form
of the POSIX path
of thisItem)
if the queryResult
is in theseTypeIdentifiers
then
return true
else
return false
end if
on error
return false
end try
end checkForIdentifier
on deriveNewFilename(sourceItemPOSIXPath, newNameExtension, incrementSeparator, targetFolderPOSIXPath)
-- A sub-routine used for deriving the name and path of a new file using the name of an existing file
-- Pass in file ref in POSIX format, the new name extension, an increment separator, and any target directory (in POSIX format)
-- Name and POSIX path for new file are returned. The name is incremented if a file exists in the target location.
-- Pass a null string for the target directory to use the item's parent directory
-- Pass a null string for the new name extension to use the item's current name extension
-- get item info
copy my itemInfoFor(sourceItemPOSIXPath)
to {parentDirectoryPath, sourceItemName, sourceItemBaseName, sourceItemNameExtension}
if targetFolderPOSIXPath
is ""
then
-- get the path to parent folder of the source item
set targetFolderPOSIXPath
to parentDirectoryPath
else if targetFolderPOSIXPath
contains "~"
then
set targetFolderPOSIXPath
to (
do shell script "echo " & targetFolderPOSIXPath)
end if
if targetFolderPOSIXPath
does not end with "/"
then set targetFolderPOSIXPath
to targetFolderPOSIXPath & "/"
-- check file extension
if the sourceItemNameExtension
is missing value then
set the sourceItemNameExtension
to ""
if newNameExtension
is ""
then
set extensionSeparator
to ""
else
set extensionSeparator
to "."
end if
else
set extensionSeparator
to "."
end if
-- generate the target file name
if the newNameExtension
is ""
then
set targetName
to sourceItemName
set targetExtension
to sourceItemNameExtension
else
set targetExtension
to newNameExtension
set targetName
to (
the sourceItemBaseName & extensionSeparator & targetExtension)
as Unicode text
end if
-- check to see if a file named the same as the source file exists in the target folder
set targetItemPOSIXPath
to targetFolderPOSIXPath & targetName
set the fileExistenceStatus
to ¬
(
do shell script "[ -a " & (quoted form
of targetItemPOSIXPath) & " ] && echo 'true' || echo 'false'")
as boolean
if fileExistenceStatus
is true then
set the nameIncrement
to 1
repeat
-- create a new target path with the target item name incremented
set the newName
to ¬
(
the sourceItemBaseName & incrementSeparator & (nameIncrement
as Unicode text) & extensionSeparator & targetExtension)
as Unicode text
set targetItemPOSIXPath
to targetFolderPOSIXPath & newName
set the fileExistenceStatus
to ¬
(
do shell script "[ -a " & (quoted form
of targetItemPOSIXPath) & " ] && echo 'true' || echo 'false'")
as boolean
if fileExistenceStatus
is true then
set the nameIncrement
to the nameIncrement + 1
else
set the targetPOSIXpath
to (targetFolderPOSIXPath & newName)
return {newName, targetPOSIXpath}
end if
end repeat
else
set the targetPOSIXpath
to (targetFolderPOSIXPath & targetName)
return {targetName, targetPOSIXpath}
end if
end deriveNewFilename
on itemInfoFor(sourceItemPOSIXPath)
-- get the parent directory of the item
set the parentDirectoryPath
to (
do shell script "dirname " & (
the quoted form
of sourceItemPOSIXPath))
--> "/Users/sal/Pictures"
if parentDirectoryPath
does not end with "/"
then set parentDirectoryPath
to parentDirectoryPath & "/"
-- get the name of the item
set the itemFileName
to (
do shell script "basename " & (quoted form
of sourceItemPOSIXPath))
--> "automator101.png"
-- get the item name without extension
set the itemNameWithoutExtension
to (
do shell script "file=" & (quoted form
of itemFileName) & ";echo ${file%.*}")
-- get the item extension
if itemFileName
contains "."
then
set the itemFileExtension
to do shell script "file=" & (quoted form
of itemFileName) & ";echo ${file##*.}"
--> "png"
else
set the itemFileExtension
to missing value
end if
return {parentDirectoryPath, itemFileName, itemNameWithoutExtension, itemFileExtension}
end itemInfoFor