I cannot be 100% certain of this, and I’m not sure if it affects KM. But I spent a huge amount of time tracking this down so I thought I’d share it. I have been developing and using software to manage desktop wallpaper for five year. I’ve used many features of KM over these years. I upgraded one of my Macs to Tahoe the other day, and it broke my software. At first I thought it might be some incompatibility with KM v. 11.0.4, but now I’m not so sure. Here’s the issue. KM looks at the display order in System Settings to figure out what the “Main” screen is and what the “second” screen is. I now think it’s doing this correctly, but the Mac Finder has different ideas. When looking at the “desktop” object, it appears that the desktop object refers to my laptop’s display as 1, and my attached external display as 2, even if the system settings makes the external display as the main display! In that case, it should refer to the external display as 1 since that’s where the menu bar is, but it doesn’t. The laptop is always 1, and the external display is always 2. Again, I might be wrong about this, but that’s what it looks like to me. It’s a bit tricky to try to fake out the Finder, and it took about 1.5 days, but I managed to do it. May software is working again. I need to do more testing.
No, it has nothing to do with order. "Main" is as set in your display arrangement, the screen with the menu bar. Order is screens from left (1) to right (n) (and also top-to-bottom, but let's not confuse things!).
So if your external is your "Main" screen but it is arranged to the right of your laptop it will have the index 2.
Can you explain how you are "looking at the 'desktop' object" (or, indeed, getting any info from Finder about screens)? That may have a bearing.
So nothing to do with Finder -- that script is using System Events.
This line:
...depends on the order of the desktops in the list being returned by a System Events every desktop call being the same as the OS's indexing scheme (which is what KM uses), but it isn't.
I can confirm that on Sequoia the "main" screen is always item 1 in System Events's list -- but that doesn't match the OS/KM indexing for my setup, where it is index 2, so that this previously matched for you was a lucky accident.
I can confirm that on Tahoe the "internal" screen is always item 1 in System Events's list -- another change is that desktop id is now an integer, where it was previously a real.
So yes -- a change in AS's System Events which, hopefully, you'll be able to find a way round.
Also, Keyboard Maestro’s screen ordering is defined based on the screen positions.
0 is the Main screen, and 1 through SCREENCOUNT() are the screens in orientation order from left to right (and top down for screens at the same position).
This numbering has nothing to do with any other screen numbering the system might use.
You can also refer to screens by names, for example Second is the left most screen that is not the Main screen (note that the Second screen may not have index 2). See: SCREEN functions.
Sadly, this kind of stuff happens all the time, usually without documentation, comment, or explanation. As developers, we often first discover it while testing our apps on new releases, wondering why some certain thing no longer works. (Nothing that was using private APIs or even deprecated APIs, just stuff that Apple changed because they felt like changing it.)
I was SVP/Software and a Corporate Officer at Apple. Left in late 1996, a month before Steve returned. It’s why I tell people I worked at Apple “between Jobs”. I initiated Mach on 68k and PowerPC.
I helped Sculley and the board invest in Acorn RISC Machines ( now ARM). You might want to review my Congressional testimony to Congress requesting wireless radio spectrum for what eventually became 802.11.
That's why I followed my comment with three separate ironic smiley faces—it was totally a joke ... I was well aware of (much of) your background. (Because I was at Apple from 1989 to 1993 myself.)