I was wondering if there is a way to programatically get a list of all windows on the screen, including windows that are outside the current application.
I will explain what I am trying to achieve. I am a linux user who recently started using a mac. I was using the fluxbox desktop manager on linux. When switching between windows, instead of pressing alt+tab repeatedly to cycle to the desired window, I was able to modify fluxbox to jump directly to the window I want. I was able to do that because fluxbox is opensource, I modified the code, setup a shortcut to give focus to a specific opened window of my choice.
I am trying to achieve the same thing on mac and I was wondering if that is even possible. It seems I can access the windows that are owned by my application, but I can't access the windows owned by other applications
I experimented with the Core Graphics library by following this post
- I first use
CGWindowListCopyWindowInfo
to a get a list ofCGWindowId
- Next I use
[NSApp windowWithWindowNumber:windowId]
to get aNSWindow
. But theNSWindow
I get arenil
except for windows that are owned by my application.
Is this the way mac is designed and we cannot access windows outside of our own application ? Or is there a way around that ? I am wondering how GUI automation tools work on Mac if Mac is designed to prevent an application from controlling windows of other applications.