I have a JavaScript for Automation (JXA) function to determine which state a macOS app is currently in:
function getAppState(appName) {
if (!Application(appName).running()) {
return "APP_NOT_RUNNING";
}
const proc = Application("System Events").processes.byName(appName);
if (proc.windows.length === 0) {
return "APP_RUNNING_NO_WINDOWS";
}
if (proc.frontmost()) {
return "APP_RUNNING_FRONTMOST";
}
// with Ventura stage manager, it seems this is all we can find out;
// proc.miniaturized/visible/zoomed won't tell us if the app has an open window on the
// screen or not
return "APP_RUNNING";
}
It tells me if an app is currently running, and if it is, if it has any application windows and if it is currently at the front.
I would like this script to return another value, let's call it APP_RUNNING_AT_THE_SIDE
when the app is shown at the side in Stage Manager mode in macOS Ventura. I mean apps in a state like those in this screenshot:
I've tried to check the properties miniaturized
, visible
, zoomed
of both Process
and Application.Window
with no luck – they always return the same values, no matter if an app is shown fully on the screen or small at the side.
Is there a way to determine if an app is at the Stage Manager side with JXA? Or perhaps someone knows an AppleScript solution that I can port to JXA?