Automating individual object animations in Keynote

Hi all,

I’ve been digging into iWork’s Applescript library, inspired by Episode 3 of Automators. What I’m trying to produce is an Applescript that will duplicate an existing slide and remove all animations contained in the slide. I often want to produce a final slide that shows the final version of the previous slide for when my animations get unwieldy.

From what I can tell, Keynote lets you automate the slide transition, but I can’t find any way to control builds within the slide. Any tips (or bad news)?

Teddy

You will need to use UI scripting (simulating key presses etc.). Here is how i did it:

See also https://www.alfredforum.com/topic/3465-problems-and-fixes-for-applescript-ui-scripting/ for a helpful discussion of pitfalls and resources.

This is extremely helpful. Thank you very much! I had to add some UI scripting to select all objects on the slide, but now working great.

There’s a great website that @Sal put together called iWork Automation, but unfortunately I didn’t find anything in the Keynote information regarding individual object animation.

Yeah I was referred to the site (which is great otherwise) by folks on macscripter at the time but no luck.

For those interested, here’s what I came up with that seems to work quite well. Thank you again @dfay for all your help! This will save me a ton of time.

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
			-- tell application "System Events" to keystroke "d" using command down
			
			-- 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
				duplicate s to after (get the current slide)
				set transition properties of current slide to {transition delay:0, automatic transition:false, transition effect:no transition effect, transition duration:0}
				properties of iWork item in current slide
			end tell
			
			tell application "System Events" to keystroke "a" using command down
			tell application "System Events"
				tell process "Keynote"
					set frontmost to true
					tell window 1
						
						-- 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
						-- edit the following to reflect your desired build
						
						if button "Change" exists then
							click button "Change"
							click button "None" of scroll area 1 of pop over 1 of button "Change"
						end if
						if button "Change" exists then
							click button "Change"
							click button "None" of scroll area 1 of pop over 1 of button "Change"
						end if
					end tell
				end tell
			end tell
		end tell
	end tell
end tell
1 Like

Hey there @RosemaryOrchard, @dfay and @tedsvo,

Wondering if your conversation can help me with Keynote as well.

I am a Bible teacher and I use Keynote for everything. My default most used slide animation is a 1 Second Dissolve. My second is Magic Move, but that is more infrequent (and more manual so I don’t care about automating it as much.

The default dissolve time for a Slide Dissolve is 1.5 seconds, which is too slow. I desperately wish I could set the default to 1 second SOMEWHERE in Keynote, but there is no way.

Is there a way to create a script that

  1. Applies the Dissolve Transition and
  2. Sets the Duration to 1.00 seconds?

I literally do this hundreds of times in a week, and yes I know that I can select them all and apply it, but then I would have to go through manually and undo all of the magic moves

The best scenario would be to write a script that applies the dissolve, sets it to 1 second and then I could take that script, create a macro in Keyboard Maestro, map it to a Stream Deck button and all would be right with the world.

Any help would be amazingly appreciated!

You have no idea what an incredibly time-saving help this would be for me.

Thanks so much

Bodie

Fortunately this can be done directly, without UI scripting:

tell document 1 of application "Keynote"
	set transition properties of current slide to {transition duration:1, transition delay:0.5, transition effect:dissolve, automatic transition:false}
end tell

@dfay You are awesome! Thank you! I will definitely be trying this out.

One follow up question: Will this action work on anything I have selected?

For example:

a) Sometimes I want to select one slide and apply a slide transition
b) Other times I want to select a range of slides and apply it to all of the selected slides
c) Sometimes I want to select an object or range of objects within a single slide and affect those

Is there a way to modify the code to do something like current slides or current selection or current object? I don’t know enough about AppleScript to know if those are even real properties, but once I know the correct syntax for a single slide (above) a range of slides and how to target objects, I think I can handle all of the transition properties from there.

Thanks so much for your help! Being able to apply these with one button press will be a dream come true!

Bodie

this works for a & b - transition properties are only found in slides so c is trickier (taking us full circle back to the first post in this thread)

tell document 1 of application "Keynote"
	set s to selection
	repeat with aSlide in s
		set transition properties of aSlide to {transition duration:1, transition delay:0.5, transition effect:dissolve, automatic transition:false}
	end repeat
end tell

@dfay Much appreciate your taking the time to help and respond. I will review the code earlier and what you taught me in this later script to see if I can get it to work.

Thanks

1 Like