ScreenName: Is there any function or token that holds the screenname value i.e. "HP LV1710"

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?

Shortcuts can also retrieve display names and set them to variables in Keyboard Maestro.

It's been around for a while, but I couldn't say for how long.

Since it shows up only when I use a 2nd monitor, which isn't very often, I didn't notice it.

There's also

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.

1 Like

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.)

NB Use containing and not matching for the condition test.

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.

Out of interest -- what's your "otherwise" doing?

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".

Otherwise only occurs if
either you are already on the screen
or that screen is offline
so I just display a message in large text to that effect.

Regarding the different names for the internal / primary screen
Originally I had

Screen Shot 2024-11-20 at 11.07.35 AM

as the wording varied depending on the app (cogwheel set to NOT abort i.e. keep going)
this version was replaced by

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.

You are correct, which is why I switched to using the keyword "Internal" instead.

Don't forget that you can use a regex in the menu item field, so long as it produces only one match:

image