For any/most applications if I go
Window> drop down
I have the choice of screenname to move to
e.g. for me the menu items are
"Move to HP L1710"
"Move to Toshiba-TV"
"Move to Internal retina display". etc
Is there any KM function or token that holds/returns the screenname value i.e. "HP LV1710"
for say a particular screenindex or "front" screene
I never noticed that before. Is that a new Sequoia feature? I just installed it yesterday.
I don't think KM has a solution, but AppleScript, Javascript and the Shell could probably get that data for you. For example, this shell command gives you the names of all the screens within its results:
system_profiler SPDisplaysDataType
Why is it that you need the name of the screen associated with its KM number?
If the monitors are different sizes, it should be possible to correlate the names from the system_profiler app with the sizes returning from the KM functions. Are your monitors different sizes?
tell application "System Events"
display name of every desktop
end tell
...which, of course, gives different names for an internal display, eg "iMac" vs Shortcut's "Built-in Display" vs the menu's "Built-in Retina display".
No idea what order the names are returned in, so you'll need to test that to see if there's some kind of consistency, @jonathonl.
I have written a set of macros on window management, but I was trying to make it generic before I published them.
As MACOS sometimes rearranges the layout of the screens for you, this in turn changes the Screenindex values and Front/Back etc whereas in KM you can now move to a NAMED window.
On your own system this works fine and is reliable, but does not work for anybody else.
Surprisingly, this works..........
(The g prefix is just to make a variable global whilst testing.)
I see. So you just need the names of the displays, and there's no need to coordinate them with the KM screen numbers.
In that case you have several options. One option is to use the AppleScript code that Nige provided, which seems to get the list of displays. Another is to use the shell command that I provided, although you may have to filter out the lines and characters that don't contain the display names.
Unfortunately, neither of these give quite the right output in testing -- external displays were named correctly but internal displays don't match the menu item. My iMac, for example, reports as "iMac" in both while the menu item is "Move to Built-in Retina Display.
Though if it's only internal displays that mis-report I guess you could use "and if no match then move to internal display".
There's a maximum of one internal display on any Mac, right? And the name is always the same, right? We can just assume that the internal display is always available. He could just hard-code the name of the internal display into his list.
I did find one oddity. Sidecar displays don't seem to show up, but they are listed under the Window menu even if the Sidecar display is turned off. Since he didn't mention using Sidecar displays, this isn't an issue for him.
Well that's a significant issue. Your code has to treat each app differently now, which is still possible, but will take more code.