How to check if window having %LastWindowID% exists ? [KM10:Question]

KM10 add this token %LastWindowID% which is window ID of the most recently displayed Keyboard Maestro Engine window.

Anyone has idea how applescript or any KM action can be used to check if the window of the specific window ID exists ?

I have tried this but it didn't work.

tell application "Keyboard Maestro Engine"
	if window id 2385 exists then    #  assume window of this window id is present 
		display dialog "is present"
	else
		display dialog "is not present"
	end if
end tell

I don’t that is correct. The wiki says: ” the window ID of the last window opened by this action” - which says to me any window opened, not just a KM window.

So your AppleScript needs to “tell” something other than the KM Engine. Maybe you could try “System Events” instead?

I really don’t know, just a guess!

tiffle,
" I don’t that is correct. The wiki says: ” the window ID of the last window opened by this action” - which says to me any window opened, not just a KM window."

Yes, that you are correct from token:LastWindowID [Keyboard Maestro Wiki]

I have copied from the following which I thought should be the same definition as in token:LastWindowID [Keyboard Maestro Wiki]

->> action:Execute a Shell Script [Keyboard Maestro Wiki]
KMINFO_LastWindowID The window ID of the most recently displayed Keyboard Maestro Engine window

Using System Events didn't work .

What I trying to do is to capture window ID of async Custom HTML Prompt window , and check if window exist without relying on the prompt's data-kmwindowid .
image

1 Like

Hey @tiffle,

After testing I believe the Wiki is telling a fib...

As far as I can see – the token is for Keyboard Maestro Engine windows only.

@macdevign_mac – as far as I know the only place that token has any use is in the manipulate a window action:

image

The window ID does NOT correspond to System Events' window ID.

@peternlewis?

-Chris

1 Like

As the wiki says, but with a typo of "action" instead of "macro", it is for Keyboard Maestro Engine windows, opened by this macro instance only. I have clarified the wiki.

Here is an example.

image

The script is:

tell application "Keyboard Maestro Engine"
	set x to getvariable "Window"
	window id x exists
end tell

The Pause does not have to be 1.5 seconds, but it does have to exist because the action is asynchronous (which it has to be or the next action would not run, and you could not get the token result) and so the window will not necessarily be created and displayed by the time the window is run.

3 Likes

Hi @macdevign_mac - I didn’t spot the wiki entry you linked to. It’s nice to know you were correct, though, as clarified by @peternlewis. I hope that sorts it out for you anyway. Cheers!

Peter,
thank for clarification and the example which work perfectly.

tiffle,
Glad that it is resolved now :}

Chris,
thank for the information.

Forgive me if you already know this, and even if you do know this, others might not:

You could have put those 3 messages in one post. You can address people just by typing an "@" followed by their screen name, like this:

@tiffle Glad that it is resolved now :}

@ccstone Thanks, Chris!

@macdevign_mac Like I said, you probably already knew this. And of course you could include Peter also.

:grinning_face_with_smiling_eyes:

3 Likes