Keynote automation with AppleScript
I am automating some process with AppleScript and Python. But I got stuck to automate printing 1 slide per page and exporting it to a PDF. I can print 3 slides per page and export it to a PDF file, but not one slide. Can anyone help me with this? This is my code so far:
tell application "Keynote"
activate
open POSIX file "{keynote_file}"
delay 5 -- Allow more time for the document to open fully
if (exists front document) then
tell application "System Events"
tell process "Keynote"
set frontmost to true
repeat until window 1 exists
delay 0.5
end repeat
click menu item "First Slide" of menu of menu item "Go To" of menu "Slide" of menu bar 1
delay 3
keystroke "p" using {{command down}}
delay 5 -- Longer delay for print dialog to open
repeat until sheet 1 of window 1 exists
delay 1 -- Ensure the print dialog has fully appeared
end repeat
click checkbox 3 of group 1 of group 2 of scroll area 2 of splitter group 1 of sheet 1 of window 1 -- HANDOUT
delay 1
click checkbox 1 of group 1 of group 1 of group 2 of scroll area 2 of splitter group 1 of sheet 1 of window 1 -- INCLUDE PRESENTER NOTES
delay 1
click menu button 1 of group 2 of splitter group 1 of sheet 1 of window 1
delay 1
click menu item 0 of menu 1 of menu button 1 of group 2 of splitter group 1 of sheet 1 of window 1 -- Try index 0 for "1 slide per page"
-- Save to the desired folder
repeat until exists sheet 1 of sheet 1 of window 1
delay 1 -- Make sure the "Save as" dialog is ready
end repeat
keystroke "g" using {{shift down, command down}}
delay 2
keystroke "{dest_keynote_folder}"
delay 2
keystroke return
delay 2
keystroke "{export_filename}"
delay 2
click button 4 of sheet 1 of sheet 1 of window 1 -- save button
delay 5
end tell
end tell
delay 5 -- Give time for the file to save
save front document
close front document
end if
end tell
MacBook Air 11″, macOS 10.15