Hello
You may try the following script. It will ask you to choose folder where Numbers files reside and then export every Numbers file in the chosen folder as PDF. Export destination folder will be the last folder you used for export. So you'd better export one file in advance and select the export destination folder you want to use. It will replace existing pdf file in destination folder.
Menu text are assumed in English and hard coded in script. For languages other than English, please edit the following three properties in export_as_pdf() handler:
property export_menu : "Export…"
property image_quality : "Good" -- Good | Better | Best
property layout : "Sheet View" -- Sheet View | Page View
The first one is menu item name of File > Export… (note … is U+2026 HORIZONTAL ELLIPSIS, which can be inputted by option ; in English keyboard for instance) and the rest are for options in Export sheet.
Tested with Numbers 2.0.5 under OSX 10.6.5.
Hope this may help,
H
_main()
on _main()
script o
property ff : {}
property xx : {}
property yy : {}
set f to choose folder with prompt "Choose folder of Numbers files"
tell application "Finder"
set ff to (files of f whose name ends with ".numbers") as alias list
end tell
tell application "Numbers" to launch
repeat with f in my ff
tell application "Numbers"
tell (open f)
if my export_as_pdf("", {_replace:true}) then
set end of my xx to f
else
set end of my yy to f
end if
close
end tell
end tell
end repeat
tell application "Numbers"
display dialog "Exported " & (count my xx) & " of " & (count my ff) & " files." giving up after 20
end tell
end script
tell o to run
end _main
on export_as_pdf(pdfname, {_replace:_replace})
(*
string pdfname : output pdf file name (pdfname = "" denotes the current name whose extension is replaced with "pdf")
boolean _replace : true to replace existing pdfname, false otherwise
return boolean : true if operation is not canceled, false otherwise (in case _replace = false and pdfname already exists)
*)
script o
property export_menu : "Export…"
property image_quality : "Good" -- Good | Better | Best
property layout : "Sheet View" -- Sheet View | Page View
property _canceled : false
tell application "Numbers"
activate
if pdfname ≠ "" then set the clipboard to pdfname
end tell
tell application "System Events"
tell process "Numbers"
tell menu bar 1's menu bar item 3 -- File
tell menu 1's menu item export_menu -- Export…
click
end tell
end tell
tell (window 1 whose subrole = "AXStandardWindow")
tell sheet 1
tell radio group 1
tell radio button 1 -- PDF
if value ≠ 1 then click
end tell
end tell
tell pop up button 2 -- Image Quality
if value ≠ image_quality then
click
tell menu 1's menu item image_quality
click
end tell
end if
end tell
tell pop up button 1 -- Layout
if value ≠ layout then
click
tell menu 1's menu item layout
click
end tell
end if
end tell
tell button 1 -- Next…
click
end tell
end tell
end tell
--keystroke "d" using {command down} -- desktop
if pdfname ≠ "" then keystroke "av" using {command down} -- select all and paste in file name
keystroke return
tell (window 1 whose subrole = "AXStandardWindow")
tell sheet 1 -- save sheet
repeat while exists
delay 0.1
tell sheet 1 -- alert sheet (already exists)
if exists then
if _replace then
click button 1 -- Replace
else
click button 2 -- Cancel
set _canceled to true
end if
end if
end tell
if _canceled then click button 3 -- Cancel
end repeat
end tell
end tell
end tell
end tell
return not _canceled
end script
tell o to run
end export_as_pdf