How can I find the id of a window?

Hello,
Some functions in KM use a “Window id”, but how can I find this specific id ?
I’ve searched in all the tokens related to windows, but I haven't found any information.

My problem is that I’m in a configuration where all windows have the same name (and I can’t change it), so it’s not possible to identify a window by his name.

Thank you in advance

As far as I know, KM can only target its own Engine windows by ID -- KM created dialogs and prompts, for example. But if you have an example of otherwise, please post it.

Application windows are referenced by index, their position in their application's window stack, front to back, with 1 being frontmost, 2 being the window behind that, and so on.

You might be able to use AppleScript to get window IDs and then, later, use AS again to do things to those windows -- but you'd still have the problem of working out which window has which ID (and that assumes that an app that can't do window titling properly has bothered to provide AS hooks!). And how you solve that should also point the way to being able to do the same with KM Actions and window indexes.

What's the mystery app, and what are you trying to do?

Thanks for your answer.

”Application windows are referenced by index, their position in their application's window stack, front to back, with 1 being frontmost, 2 being the window behind that, and so on.”

I know that, and that's precisely the problem!

I need to bring a specific window to the foreground so that I can then interact with it. The “relative” position of a window in the window stack is therefore of no use to me, as the index can change at any time.

Currently, I have positioned my windows with a natural offset (automatic positioning when each new window is opened).

To bring one of them to the foreground, I click on the corner of the correct window that is always visible.

This has been working for months, but it's not very “clean” programming. The slightest accidental movement of a window, or if another window is opened on top of my improvised “handles,” and my whole process collapses.

The ideal solution would be to have a UNIQUE and INVARIABLE identifier for each window so that I can always bring the right window to the foreground when I need to.

And as I mentioned, I can't call a window by its name, because they all have the same name, generated by Mac OS.

Nothing mysterious: I'm monitoring several instances of the same iOS app running on multiple sessions on a Mac Studio M1Ultra.

This monitoring allows me to view and perform actions on these app instances through shared windows.

The problem is that Mac OS itself defines the name of my screen sharing windows (it's always the name of the Mac Studio) and it's impossible to change this name.

So I have a stack of windows with the same name and I want a sure and precise way to address the right window to perform my actions.

So the app is Screen Sharing.

Have you tried Apple Remote Desktop instead? It may seem like overkill but it is (at least in v3.9.7) AppleScriptable, and this works:

tell application "Remote Desktop"
	set name of window 1 to (name of window 1 & "-1")
end tell

So I'm thinking you could rename each window as you open it, incrementing the postfix each time, and then your window names will serve as identifiers.

The only case where Keyboard Maestro uses window id is to reference Keyboard Maestro Engine window ids (see: wiki).