MacOS – Determine the count of open windows for running app

macos

After switching to an app with Cmd + Tab, which has multiple windows open, if the frontmost window in not the desired one, additionally Cmd + ` needs to be done to reach the desired window. But at times, the latter shortcut may not effect a switch when the target app has only single window open.

Is it feasible to determine the total count of open windows for the target app? (E.g. by having the count of open windows shown under the app icon in app switcher UI or in the Dock)

Best Answer

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.