Help with Super-Basic Keynote AppleScript, please!

Hello Friends!

I am trying to Modify Sal Saghoian’s AppleScript and Keynote Slide Transitions code to make one simple AppleScript.

I have owned Script Debugger for years, but just haven’t needed it, but I need to script one small thing in Keynote and I don’t know enough about the basics of scripting to know what I am doing wrong.

What I want to do is this:

  1. Select a slide in Keynote manually
  2. Run a script that tells that slide to apply a 1 second Dissolve transition.

That’s it!

Here is as far as I have gotten, but it doesn’t work because I don’t know what I am doing. Most of you will know immediately what is wrong. Would you please help me fix this code so it works?

Thanks so much!


activate application "Keynote"
tell application "System Events"
tell process "Keynote"
	set thisSlide to current slide
	tell thisSlide
			set the transition properties to
					{transition effect:dissolve, transition duration:1.0, transition delay:0, automatic transition:false}
	end
end tell
end tell

Script debugger tells me

Expected end of line but found identifier.

Thanks so much!

I don’t have Keynote, so I can’t get it’s dictionary.
But I guess you have to define a document first.

Your code looks like GUI Scripting (“System Events”, tell process “Keynote”). For direct Keynote scripting You must use tell application “Keynote”:

tell application "Keynote"
	set thisSlide to current slide
	tell thisSlide
		set the transition properties to {transition effect:dissolve, transition duration:1.0, transition delay:0, automatic transition:false}
	end tell
end tell

@spherico you were right, I had to adjust the very helpful code and advice from @Dirk to include the document. It works!

	tell front document
		set thisSlide to current slide
		tell thisSlide
			set the transition properties to {transition effect:dissolve, transition duration:1.0, transition delay:0, automatic transition:false}
		end tell
	end tell
end tell

The only issue I have left is selecting a range. Instead of current slide how to I write it so that it affects “whatever slides happen to be selected at the moment”?

Once I get that figured out, I am in the clear!

Thanks for your help.

You can try this, but I don’t know how can I detect if the selection is not a slide without the error routine. But I think it work’s:

tell application "Keynote"
	tell front document
		try
			set theSlides to selection
			repeat with theSlide in theSlides
				set the transition properties of theSlide to {transition effect:dissolve, transition duration:1.0, transition delay:0, automatic transition:false}
			end repeat
		on error errMsg number errNum
			-- no slide selected
		end try
	end tell
end tell