macOS - Determine the count of open windows for running app
No - there's not a general solution for this. You might need to add a follow on question explaining why you need this information and what you'll want to do once you have that information. Some apps are well behaved and you can use automation to request a count of active windows or use Mission Control or script things in python with an objective C bridge to count all windows based on your definition of “open” whether it excludes hidden / minimized / on another virtual space or screen or just the windows visible.



Keep in mind if you’re scripting things, with App Nap / Sudden Termination / Power Nap and all the advanced power scheduling technology that's been added to macOS - you can't really even define if some apps are even running. You will have an app running and show up in the dock and app switcher when each and every thread of that app is killed and nothing is running on the kernel. Similarly - you can have threads running on the kernel - doing active work when the app is technically not running and you won't see it in the dock or the app switcher.

Quite simply, the OS and applications deeply integrate to start and stop things and the illusion that an app is running is no longer something you want to manage. You should expect that when you switch to an app or launch an app, that it responds quickly and lets you get back to work regardless of the status of it running or not before you asked it to do work.