0

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:

screenshot of apps at the side of the screen in macOS Ventura Stage Manager

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?

Patrick Hund
  • 19,163
  • 11
  • 66
  • 95
  • New macOS features are highly unlikely to be AppleScriptable: AppleScript is moribund and at the tail end of its lifecycle, JXA was a miserable half-assed failure that sank on launch, the Mac Automation department was eliminated in 2016 (see JXA), and Apple clearly intends cross-platform Siri + Shortcuts to be the future of (end-user) automation. You should check Shortcuts, Swift, Cocoa, and other standard frameworks to see if any of those provide the functionality you need, otherwise you’re probably SOOL. – has Nov 23 '22 at 17:19

0 Answers0