I would like to be able to generate a list, and hopefully access one-by-one, all the open windows of any specific app no matter what desktop they are in,together with which Desktop Workspace (Mission Control Space) each is in.
In general, AppleScript and other Apple tools seem to only be able to list those that are visible in the active Desktop Workspace (which seems pretty dumb and like Apple internally doesn't really know how to use the Mission Control feature).
Many apps have a Windows menu that lists all the open windows of that app, but that seems like I would have to have specific macros to manage the lists for each different app. That's not ideal. And it's not complete, because those in-app lists simply list the window title, file name, or whatever and not the Desktop Workspace.
Specifically, to start, I want to list all the open TextEdit windows and all the open Typora windows. They have very different UIs for showing that list themselves.
Eventually, I would like to have a small app window in the corner of each Desktop Workspace that displays a name or other ID for that desktop space. Then I could change to a different desktop by activating that app window and then putting it in the background.
Most significantly, this would allow me to change to the same working desktop even if I have rearranged the order of desktops in Mission Control (because the target window would move with the whole desktop). Normally, Mission Control changes the numbering of the desktops and the assigned hotkeys then point to whatever desktop is now in that numerical position. IMHO, this is one of the key flaws in Mission Control that has kept people from using it extensively.
So far I have found the Apple JSX method/function $.CGWindowListCopyWindowInfo(16, 0)
The first argument sets some filters on the data returned. Here 16
is the value of the constant $.kCGWindowListExcludeDesktopElements
, which excludes desktop icons, the desktop itself, and some other "windows" that can't be seen. The second argument is a window ID to allow you to select windows in front of or behind that specific window, so 0
shows all windows.
That method typically dumps hundreds of items that need further filtering and massaging. Here's one entry as formatted by js-beautify:
$({
"kCGWindowLayer": $(0),
"kCGWindowAlpha": $(1),
"kCGWindowMemoryUsage": $(1248),
"kCGWindowSharingState": $(1),
"kCGWindowOwnerPID": $(1410),
"kCGWindowNumber": $(322),
"kCGWindowOwnerName": $("TextEdit"),
"kCGWindowStoreType": $(1),
"kCGWindowBounds": $({
"X": $(0),
"Height": $(679),
"Y": $(23),
"Width": $(385)
}),
"kCGWindowName": $("Which Apps Have I Used.rtf")
}),
In this example, the kCGWindowBounds
place it at the left margin of the screen, at the top (immediately below the toolbar), a bit taller than it is wide. Fine. But it doesn't tell me that in Mission Control it's in Desktop 16
.
If I had multiple displays, I could figure out which display it was in because those values treat all the different displays as a single desktop. An X
value of over 1440 (the width of my laptop display) would put it in the monitor to the right of my laptop, if my laptop was leftmost.
But HOW do I determine which Mission Control Desktop Workspace that particular app window is in? Especially, how do I determine that for a number of windows, without having to actually activate and go to each window to find out which desktop is now active?
There are some apps that have been able to do something like this in the past, notably HyperSpace and CurrentKey, but HyperSpace didn't work beyond OSX 10.11 and CurrentKey has been withdrawn due to time limitations on supporting a free app and inability to support the Monterey OS.
.
Any ideas?
Q
to got to my Projects Queue desktop than it is to remember that that is Desktop 17.