use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
property alert_exists : "The PDF already exists. Continue?"
property dialog_yes : "Yes"
property dialog_no : "No"
property export_complete : "The PDF has been exported"
# this script exports a PDF of the frontmost Numbers file
# the Numbers file is saved before export to make sure that it exists
# the PDF file is exported to the same folder as the original file
# if the name of the original is myName.numbers, the PDF name is myName.pdf
# if the PDF already exists it is possible to cancel the export
# once the export is completed, Numbers displays an alert
# and Finder opens the enclosing folder
tell application "Numbers"
# this script exports a PDF of the frontmost Numbers file
set myDocument to (item 1 of (document of windows whose index is 1))
# the file is saved before export to make sure that it exists
save myDocument
set myDocumentName to name of myDocument
set myDocumentPath to file of myDocument as text
end tell
tell application "Finder"
# the PDF file is exported to the same folder as the original file
set myDocumentContainer to (container of file myDocumentPath) as text
end tell
# if the name of the original is myName.numbers, the PDF name is myName.pdf
set myExportedPDF to myDocumentContainer & myDocumentName & ".pdf"
tell application "System Events"
# if the PDF already exists it is possible to cancel the export
if exists file myExportedPDF then
display alert alert_exists as warning buttons {dialog_yes, dialog_no} cancel button dialog_no
end if
end tell
tell application "Numbers"
(close access (open for access (myExportedPDF)))
export myDocument to file myExportedPDF as PDF with properties {image quality:Best}
# once the export is completed, Numbers displays an alert
display alert export_complete
end tell
tell application "Finder"
# and Finder opens the enclosing folder
activate
open myDocumentContainer
end tell
# here again, save this script as an Application, with a funny name
# so that you can easily call with with Spotlight
# I chose "> Numbers → PDF"