How do I tell PowerPoint to bring a window to the front?

I have a window ID and need to bring the window to the front. The following AppleScript seems to work for all applications other than PowerPoint:


tell application "xxxx"
  activate
  set the index of window id 12345 to 1
end tell

If it’s a PowerPoint window, then the above script fails on the set the index… line with a “Expected expression but found property or key form” error.

Can anyone tell me what the syntax is for bringing a window to the front in PowerPoint? Thanks!!

Hello.

I think you must specify what kind of window it is, for the id property to work! :slight_smile:


tell application "Microsoft PowerPoint"
	set a to its presenter view window
	set a to its slide show window
	set a to its document window
	set a to its basic window
end tell

And maybe it doesn’t work to just set the index of that window to 1, but we’ll take it form there.

I can find the window if I use “get every document window” and iterate through them, but they don’t seem to have an ID property, so I will have to use the name, which isn’t guaranteed to be unique, so not as good as using he ID.

However, even when I have the window, I still haven’t been able to figure out how to get it to come to the front in PowerPoint. Setting the index produces an error, setting it’s visible or zoomed property to true seems to have no effect, etc. Any idea what I can do with the window to get it to come to the front?

Hello.

I think the name of the window should suffice, reading through the dictionary of powerpoint, I see that the id is missing as a property and the index is named entry_index.

Drop powerpoint onto the library window of AppleScript editor to get access to it, if you don’t have it, there you can read through what properties, and commands PowerPoint provides.

This little snippet puts the previous last PowerPoint window (of two) to the foreground.


local a, b, c
tell application "Microsoft PowerPoint"
	set a to its last document window
	set b to entry_index of a
	set c to id of its document window b
	--> missing value
	select its document window b
	end tell

or


tell application "Microsoft PowerPoint"
	select last document window
end tell


:slight_smile:

The whole point was really to show how to access a window by entry_index, which you maybe must type as entry index.

I think you should be able to use the name of document window to access a window as well.

Other reference forms like last window, or middle for that matter, would also work of course, but doesn’t serve as a meaningful identificator of a window.

If you just want to bring the active PowerPoint window to front, in front of the previous active app, then this line would suffice:

do shell script " open -b \"com.microsoft.Powerpoint\""

Thanks, that was the clue for me to get this figured out!

Using “select” on the document window was the way to get it to bring the window forward.

For anyone else searching for similar solutions, it turned out that I also had to do this for Microsoft Word and Excel which also don’t honor the “set index” command. For them, you need to use “activate object” on the “window” of the given name (as opposed to “document window” in PowerPoint).

Here’s a little more info in case anyone finds this via a google search. If the window was minimized, then it doesn’t automatically un-minimize when select (PowerPoint) or activate object (Word and Excel) is called on the window. But if you do “set collapsed of w to false” (if w is your window object) before activating the window, it will un-minimize.

Hello.

Windows also have a hidden property, this has to be set to false before activating it.

I don’t think you can resize or position a hidden window, but I may be wrong in that.