0

Using the following block of code

Application("System Events")
  .applicationProcesses.where({ backgroundOnly: false })()
  .forEach((app) => {
     app.windows().forEach((window) => {
       console.log(window.name());
     });
  });

I can access a list of all window names for currently running applications. However, for my particular use case, this code is too slow to be useful. I have been looking into the Objective-C Bridge for JavaScript scripting and have been able to list all running applications, but not the windows for those applications.

const runningApps = ObjC.unwrap($.NSWorkspace.sharedWorkspace.runningApplications)
  .filter((app) =>
    app.activationPolicy === $.NSApplicationActivationPolicyRegular &&
    !ObjC.unwrap(app.hidden)
  );

So my question is: Which Objective-C API gives me access to a list of windows for running applications?

Note - I have seen other posts that ask similar questions to this, but I have not been able to get anything working from those answers as I am unexperienced with Objective-C.

Espresso
  • 740
  • 13
  • 32
  • Does this answer your question? [Is it possible to get a full list of windows of running apps?](https://stackoverflow.com/questions/47163400/is-it-possible-to-get-a-full-list-of-windows-of-running-apps) – Willeke Feb 14 '22 at 21:07
  • I still cannot figure out how to apply the answers in that post to my problem. I tried `ObjC.unwrap($.CGWindowListCopyWindowInfo($.kCGWindowListExcludeDesktopElements, $.kCGNullWindowID))` which gives me an `[object Ref]` in return. But I cannot figure out how to cast that to an array. – Espresso Feb 14 '22 at 22:05
  • `CGWindowListCopyWindowInfo` returns a `CFArrayRef` of `CFDictionaryRef` that is bridged to a `NSArray` of `NSDictionary`. – Willeke Feb 15 '22 at 08:51

0 Answers0