Targeting palette window in Keynote

I am trying to target the so-called "Build Order" palette window in Keynote to move and resize it. This window type is not targeted via KM's "the window with title…" option. Is there a workaround for this, perhaps via AppleScript?

There's probably a way to do this "correctly" with AppleScript, which I don't know how to do, but if you want to consider another option, you can use the Move Mouse action in KM and set it's coordinates to the value of the location of the red and green dots in the upper left corner.

image

The above example will move the dialog box down/right 10 pixels. It seems to work fine. I can't upload the macro/action here because doing so would likely fail you because it contains a screen capture of the red/green dots which probably have a different resolution that your monitor has. So you will have to create this yourself.

Using this same technique, you could also resize the window. Getting the lower right coordinate of the window would require adding some numbers together (using the location of the red/green dot and the location of the Preview button at the bottom.)

1 Like

Cheers. It is a good idea, but it would clash with other palette windows that may be opened, such as the colour palette. I want to address this specific window or other ones individually.

Test this and see if it works:

AppleScript (click to expand/collapse)
tell application "Keynote"
	try
		tell (first window whose name is "Build Order")
			set its position to {25, 25}
			set its size to {750, 450}
		end tell
	end try
end tell

If that works, then it’s a good start, and you can do a lot with AppleScript to move/position that window. I can help you polish it if you need.

1 Like

I don't think you are right about the "clash" because only ONE window can have red/green buttons at any time. The other windows have the buttons "greyed out."

1 Like

Thank you! I appreciate your effort. I don't know if Keynote is misbehaving, but targeting the window by name in AppleScript and KM does not work, which I figured out when trying to run your script. :face_with_monocle:

Ah, of course! Still, I think it would be easier to manipulate the window "directly" so to speak…

Sure! I did say AppleScript was more correct. I just have tons of experience solving difficult problems using built-in KM actions.

1 Like

Try running the AppleScript directly from the Script Editor app, or better yet the Script Debugger app and let me know what the error says.

If I run this script in the AppleScript editor:

tell application "Keynote"
	activate
	set winlist to every window
	repeat with win in winlist
		set the_title to name of win
		if the_title contains "Build Order" then
			activate
			set index of win to 1
		end if
	end repeat
end tell

…then I get no results matching the name of any palettes opened—only the names of any document windows currently open.

Example (Only a new document open - together with colour and build order palette):

tell application "Keynote"
	activate
	get every window
		--> {window id 1773, window id 440}
	get name of window id 1773
		--> "Untitled"
	get name of window id 440
		--> ""
end tell

Ah, I think I am getting closer to why. I took the red pill and found this from the Apple Scripting interface guidelines:

application is the root of the containment hierarchy. That is, it contains, directly or indirectly, all the objects belonging to the application. window elements are only those application windows that contain other scriptable objects, such as document windows – modal dialogs, sheets, and formatting or tool palettes should not be included. (Palettes may be included as properties, however.)

It seems like it is pretty impossible to target a palette using Applescript, at least. Unless KM has a built-in workaround, or if some hefty UI scripting using Shell should be used…?

Well, you could always use the one-line solution that I proposed.

1 Like

Indeed. The only thing about that procedure is that often, all palette windows are inactive when I need to target one specifically, so I also need to try and capture the name of the window as well. I think KM is not capable of this, but I will test this.

Ahh, you didn't mention this. I can't duplicate your problem because I can't create two of those windows at the same time. From what I can see, only one of those windows can be open in total for Keynote.

Yes, I didn't mention it because I just realised :smile: I will check it out later today and write back!

And that took a while :sweat_smile:. But I tried, and I cannot make it work, unfortunately. Unless KM can handle this in the future, I will have to let that one go for now…

hello @cdthomer
I very much like your script. I would like to put it in my global macro group. How would I modifiy the script to make it universal, ie the frontmost window of any app ?
thanks very much

This may or may not be possible since some apps don’t have a lot of AppleScript support... however, that being said, you can try the following script. It gets the name of the frontmost app, then tells that apps frontmost floating window to adjust it’s size and position. Feel free to change those values accordingly.

I can’t guarantee it will work for everything though.

AppleScript (click to expand/collapse)
set frontApp to name of application (path to frontmost application as text)
tell application "System Events" to tell application process frontApp
	tell (first window whose subrole is "AXFloatingWindow")
		try
			set its position to {50, 50}
			set its size to {500, 500}
		on error
			display notification "Error moving " & frontApp & "'s front palette"
		end try
	end tell
end tell
2 Likes

great ! thanks very much !

You’re welcome. Additionally, if you want to specify a title, you can modify the AppleScript by changing the following line:

tell (first window whose subrole is "AXFloatingWindow")

to the following...

tell (first window whose subrole is "AXFloatingWindow" and title is "PUT TITLE HERE")
2 Likes