How do I get the name of the frontmost window?

I didn’t see anything that appeared to do it in KM, so I tried

tell application "System Events"
    tell front window of (first process whose frontmost is true)
      return get value of attribute "Name"
    end tell
  end try
end tell

And got

osascript: OpenScripting.framework - scripting addition "/Library/ScriptingAdditions/Adobe Unit Types.osax" cannot be used with the current OS because it has no OSAXHandlers entry in its Info.plist.


See the WindowName token

The specified AppleScript extension (Adobe Unit Types.osax) is too old to use on your current system. You need to either update it or remove it.

It is only a warning, and wont affect your scripts (so you could just set the Execute an AppleScript action to ignore the result, but that is not a good long term strategy)

Hey Ed,

It takes a while before you think about those darn text-tokens. :smiley:

On another note – your AppleScript is incorrect. The try block without an error-handler is masking the error – there is NO “name” attribute for windows available from System Events.

There is a “name” property.

Try this:

tell application "System Events"
  tell (first process whose frontmost is true) to return name of window 1
end tell

Also try these and note the difference:

tell application "System Events"
  tell (first process whose frontmost is true) to return attributes
end tell
tell application "System Events"
  tell (first process whose frontmost is true) to return properties
end tell



So would you use the WindowName token to return a value of a floating window asking you if you want to save or not that doesn't return a title? I tried UI browswer and was able to see that it was Window 1 and press cancel but I am trying to make Keyboard Maestro wait until it displays that window before pressing cancel.

activate application "Microsoft Excel"
tell application "System Events"
  tell process "Microsoft Excel"
    click button "Cancel" of window 1
  end tell
end tell

I know I can use this but would like to find out if every window has a referenceable name or ID for Keyboard Maestro?


Hey Adam,


Keyboard Maestro doesn’t see all possible window types.

I have several tools on the forum to help analyzing windows for use with Keyboard Maestro and/or System Events.

See this one:

List Windows Keyboard Maestro Can See v1.1

For what you’re doing the Pause Until action is probably the most simple and efficient method, although it can be done with AppleScript and UI-Scripting.


@ccstone has given you the direct answer to this question.

Here's another way to find out the window name in your specific case.

Create a test macro with just one Action:


Make sure you keep the KM Editor window open so you can see this macro/action.
Now invoke the Excel event which causes the popup.:


Keeping Excel frontmost, observe the KM Action:


If the popup window had a name/title, it would be shown in the area with the red rectangle.

So, here is how you can use this information: An Example Macro

MACRO:   TEST for Excel Front Window to Save

~~~ VER: 1.0    2018-04-15 ~~~


TEST for Excel Front Window to Save.kmmacros (3.1 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


This example works like a charm for me, running Microsoft Excel 14.7.2 (Office 2011) on macOS 10.12.6.


Very handy, thanks for sharing!

Good to know, I will stick with the Pause Until then.

Me too, this is very cool and I'll keep this on hand to use as my building block for future macros. I will no doubt use this quite often!!

Thanks for typing "currently maybe" your visuals were very helpful.

Sorry to ask the painfully obvious but I have made too many wrong assumptions in the past about things.
Step one is not needed for this. I would run step one alone first before I make the macro and then turn it into steps 2 - 4 by themselves right?

Running this macro as is really only is needs step 2 & 4 (steps one and three are just extra, though they are my question of course). No reason you would ever run a macro like this right? I know you were giving it to me as an example of which I will use often but just wanted to be sure.

Wrong. Step 1 is required, getting the name of the window BEFORE the popup window appears.
You need this when the popup window does NOT have a name, like in my example.

Wrong. While this is just an example, it is a real-world example. Obviously the conditions/criteria under which you might use this pattern will vary, and therefore you will need to adjust the macro accordingly.

If you know the title of the popup window, then you would change the “title is not” to “title is”, and enter the actual title of the window. You would NOT use the KM Variable.

Step 4 is the action that you want to perform when the window appears. In this case I want to “cancel” the attempt to quit Excel.

I did NOT type “currently maybe”. That was displayed by the KM Editor, and the screenshot just skewed it for some reason.

Feels strange to quote myself but I’m glad I asked, you proved me right by how many times I was wrong ;). Thank you.

1 Like

If there is any doubt that you cannot resolve by non-destructive testing, it is always best to ask.

Just so you know, I am always glad to answer questions. But you, and everyone, should know that the best teacher is good 'ole proven trial-and-error method. We learn mostly from our mistakes. :smile:

1 Like

Yup, absolutely I tried everything I typed about, searched the forums and Internet and have macros set for that before I bother people. Sometimes I just don’t even know what to search for like Chris’ awsome post of getting the front window (list of windows Keyboard Maestro can see didn’t occur to me to search for). I thought all my conclusions were correct based on my testing. I still have no idea how you got “Currently Maybe.” I have run it with the quit window open already, without it open and watched the macro along the way and only get “Currently True” or “Currently False.” I don’t know how Currently Maybe is even possible.

Hey @skillet,

I think this is a good example of when a new thread is desirable.

Something like “How to Quit Microsoft Excel and Save Unsaved Documents Gracefully”.


Yup no problem, I actually don’t want to quit Excel though and really just wanted to focus on how to properly identify the save pop up window in Excel. For some reason with some VBA I run it only works once I quit and then escape which most defiantly would be a new thread. Sorry for hijacking the thread to focus on getting a window name, I see how it works though in any application which is very helpful. My apologies for being too specific in using Excel in this case.

Keyboard Maestro (editor) asks the Keyboard Maestro Engine for the true/falseness of the condition when it displays the current value of a condition in the action. Keyboard Maestro repeatedly asks the engine about this every second or so for each visible condition (this is why if you have an expensive condition like an image search or a JavaScript, then you can see high CPU usage while the editor is just sitting there and the engine is not executing any macros).

Currently Maybe shows up before Keyboard Maestro editor gets an answer from Keyboard Maestro Engine as to the true/falseness of the condition. So you should generally never see this, and it will usually indicate a problem with the editor communicating with the Keyboard Maestro Engine (an issue that the Assistance window checks). Either the Keyboard Maestro Engine is not running, or some problem communicating with it has happened (which I suspect happens when something goes wrong with the interprocess communication system).


I like that, well said. Perhaps that is common lingo for all of you that walk in different circles than I.

Even computers have little wars who woulda though? All jokes aside thank you, I’m always learning from you guys!