applescript vs. keynote

hello,

i'm having a strange problem with applescript+keynote. when i try to use system events to invoke menu commands via a script like

click menu item "Copy Animation" of menu bar item "Format" of menu bar 1

(inside of enough tell...-brackets).

the problem seems to boil down to the fact that (at least on my computer) the following script returns {}

tell application "System Events"
	tell process "Keynote"
		return entire contents of menu bar 1
			click menu item "Copy Animation" of menu bar item "Format" of menu bar 1
	end tell
end tell

this script works for every app i've tried it for, but not keynote, where it always returns {}

i see two possibilities: keynote is fundamentally broken in a way that its menu bar circumvents the canonical process to make a menu bar, or keynote is broken on my machine, in which case (i already reinstalled) i'm wondering what i can do to restore a good version.

thanks for any help in advance

peter purgathofer

Answered by hci_studio in 868188022

well, what would you know, i solved this myself!

it turns out, keynote starts not one but TWO application processes, both named »keynote«. the first process has no menu bar, i suspect it is there for presenting; the second process though has the menu bar and can be addressed properly.

the script from my original post (as corrected in the first comment) works well, if it is written like this:

tell application "System Events"
	set goodK to id of second application process whose name is "Keynote"
	tell application process id goodK
		return entire contents of menu bar
	end tell
end tell

so far, the SECOND process was always the 'good' process 🤷

sorry, i copied the wrong script in my original posting, but i can't find a way to edit it...

here is the correct one:

tell application "System Events"
	tell process "Keynote"
		return entire contents of menu bar 1
	end tell
end tell

Accepted Answer

well, what would you know, i solved this myself!

it turns out, keynote starts not one but TWO application processes, both named »keynote«. the first process has no menu bar, i suspect it is there for presenting; the second process though has the menu bar and can be addressed properly.

the script from my original post (as corrected in the first comment) works well, if it is written like this:

tell application "System Events"
	set goodK to id of second application process whose name is "Keynote"
	tell application process id goodK
		return entire contents of menu bar
	end tell
end tell

so far, the SECOND process was always the 'good' process 🤷

after some more investigating, i found that the reason i have a second application process named »keynote« is because stream deck creates it when starting up.

this is a really stupid situation, and i will write to elgato about it, maybe they can do something about it, so that the application process name in applescript is NOT identical to the legitimate process.

i had quite the extensive (and somewhat productive) dialog with my self (more of a monologue then)... i'll leave it here in case anybody ever has the same problem and is looking for a solution.

applescript vs. keynote
 
 
Q