I am trying to automate the process of selecting builds for text fields in Keynote 6. Unfortunately they are not exposed to Applescript so I am doing it with UI scripting.
The problem is that after the script clicks the button to change the build and selects the new build, the contents of the window are no longer available to system events.
Here’s the script:
tell application "System Events"
tell process "Keynote"
set frontmost to true
tell window 1
-- open the toolbar if it's not open already
if toolbars is {} then
click menu item "Show Toolbar" of menu "View" of menu bar item "View" of menu bar 1
end if
-- getting the properties of the default body item also selects it in the UI
tell document 1 of application "Keynote"
set s to current slide
properties of default body item of s
end tell
-- open the animations pane if it's not open already
if value of radio button "Animate" of radio group 1 of toolbar 1 is 0 then
click radio button "Animate" of radio group 1 of toolbar 1
end if
-- deal with existing and new animations
if button "Change" exists then
click button "Change"
click button "Appear" of scroll area 1 of pop over 1 of button "Change"
set s to entire contents
else if button "Add an Effect" exists then
click button "Add an Effect"
click button "Appear" of scroll area 1 of pop over 1 of button "Add an Effect"
end if
end tell
end tell
end tell
return s
as it is, this returns {}
if the line “set s to entire contents” is moved up above the line that clicks “Appear”, s contains the contents of the window as expected.
Also, if I run the following subsequently (to complete the desired process), in a separate script, it works perfectly:
tell application "System Events"
tell process "Keynote"
tell window 1
click pop up button 2 of scroll area 1
click menu item "By Bullet" of menu 1 of pop up button 2 of scroll area 1
end tell
end tell
end tell
but if I include this code in the first script, or call it using a run script command from the first script, I get
error “System Events got an error: Can’t get scroll area 1 of window 1 of process "Keynote". Invalid index.” number -1719 from scroll area 1 of window 1 of process “Keynote”
Surprisingly, the same thing happens if I call both of the scripts in sequence from a single bash script using osascript. But it I run each separately on the command line using osascript, the second one works fine.
No doubt this is a weird Keynote bug but if anyone has any suggestions I would be very grateful! If I can get this working it will save me a few hundred clicks a week