Pause until menu item is enabled in a specific (background) application

Hi I noticed there's an action to pause a macro until a menu is enabled, which is great if the application you're using it on is in the front, but I was wondering if there was a way to use this for applications that are in the background.

A little bit about my use case, I run an analyzation process in an app that takes some time and I want a way to know when it's finished so I can bring it back to the forefront and run it again while continuing to multi-task. I used to use a pause until function that identified the front window of the application and if its name was no longer "analyzing" it would then send the alert, but upon updating this app it seems KM no longer is able to return a name for the front window, so I'm looking for other solutions. I found that when a pop up window exists it grays out the menu options so as long as I stay in the app I can use the menu to tell if the pop up is there or not, but when I move to a different app it stops seeing that menu status.

Another thought would be is there a way to use the WindowSize token to get information on the front most window of the specific application when it's in the background? The pop up is always a smaller size.

I doubt applications consistently update their menus while in the background, so I probably would not support that directly, but you could try using some AppleScript to access the menu and see (hopefully AppleScript/Accessibility folks on the forum could help you with how to do that, I don't really know myself).

The same would be true for looking at background windows. Keyboard Maestro doesn't have direct ability to do that., but AppleScript could presumably do it.

Ah ok, thanks for the response Peter! Unfortunately AppleScript a bit beyond my skill level.

In this case, largely mine too, but hopefully others on the forum with more AppleScript/Accessibility knowledge can help.

OK, I used Wavelength (Mac app) and asked the AI to write an AppleScript to do this and it got close enough that I think this works:

tell application "System Events"
	tell process "BBEdit"
		set menuItemEnabled to enabled of menu item "Save" of menu "File" of menu bar 1
	end tell
end tell

Worth trying anyway.

It works! I combined it with a repeat until action that periodically checks the window, thank you so much for the help!

1 Like