Pasting clipboard into new blank Keynote slide


I’m having troubles creating a script to paste into Keynote on a new (blank) slide. If there is an active presentation I want to create a new slide in that active presentation and paste into it otherwise create a new presentation and paste into the first slide (created for you)

I got something working, but is very slow leaving time for my users to interfere with the script. Users in our application can right click on text or images and one of the options is to “Send to Keynote”.

My script (attached) successfully detects running presentation and creates a new presentation if needed, it successfully sends a command-V to the application.

It is the middle section (select the “Masters” toolbar button to change the newly created slide to a ‘Blank’ side).

Running the script it pauses for 6-7 seconds before it navigates (5 “key code 125” messages) to the correct menu item on the popup menu. I’ve tried adding a manual delay (0.5) and still get same 6-7 second wait

I do see some feedback in the event log about a missing value between my menu button click and the first “key code 125”. It shows in the log after the 6-7 second waiting period has elapsed.

Thanks for the help

tell application "Keynote"
	if (slideshow count) ≤ 0 then
		make new slideshow
		tell slideshow 1
			make new slide
		end tell
	end if
	tell application "System Events"
		tell process "Keynote"
			click menu button "Masters" of group 4 of tool bar 1 of window 1
			key code 125
			key code 125
			key code 125
			key code 125
			key code 125
			keystroke return
		end tell
	end tell
	tell application "System Events" to keystroke "v" using {command down}
end tell