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.