Understanding SCREENVISIBLE(Main,Right)

Hi: I have a question about how I can better use the Wiki. I was having trouble with a macro that would move my current window to the right edge of my MacBook Pro.

When I used SCREENVISIBLE(Main,Right), what I expected was the right edge of the window to be up against the right edge of the screen. Instead, it moved the window off-screen to the right, leaving just about 40 pixels of the left edge of the window visible.

So I went to the Wiki, and searched, and looked at a few pages like function:SCREEN [Keyboard Maestro Wiki] but did not find anything that I understood to mean that my expectation was wrong. (Such as, when using RIGHT, it will align the left edge of the window to the right.)

So I came to the forum, and while I didn't find a post matching my question, I found similar posts, and figured out that this would work:
SCREENVISIBLE(Main,Right)-WINDOW(0,width)

My question is, if I want to be better at finding solutions in the wiki, like I must subtract the width of the window in order for "right" to mean "right", is there some foundational post/page that I can study that will help me develop that skill? Any guidance is greatly appreciated. Thank you.

In Keyboard Maestro, if you hold down the option key and select from the Edit menu, Insert Function, and then Help: SCREENVISIBLE, it takes you to the SCREENVISIBLE function wiki page.

This is a shared page for the related SCREEN and SCREENVISIBLE functions.

Near the top it says:

The SCREEN() and SCREENVISIBLE() functions return the position or size of a screen. SCREENVISIBLE() refers to the visible section of the screen, excluding the menu bar and the dock.

So the function is returning the position or size of the screen. Near the end it explains:

Coordinates are in absolute nominal resolution pixels relative to the top left corner of the main screen.

In the page it explains that Main is:

the screen with the primary menu bar (as configured in the Displays preferences).

So SCREENVISIBLE(Main,Right) is the position of the Right edge of the Main screen in absolute nominal resolution pixeks relative to the top left corner of the main screen.

So if you move a window there, you are moving the top left corner of the window to the right edge of the Main screen, which is rarely what you would ever want to do.

So that function is giving you the position of the right edge of the main screen minus the width of the front window.

So in moving the window, you are specifying the top left corner of the window, so that will move the left coordinate of the window to the right edge of the main screen minute the width of the window (thus the right edge of the window will align with the right edge of the screen).

Learning foundational information is always tricky because it can't be explained everywhere it is used and it goes on forever, depending on ever more foundational knowledge.

So in this case the primary foundational knowledge is that the entire display area is made up of one or more screens arranged relative to the main screen in the System Settings, Displays, with the top left corner of the main screen being the 0,0 point. Screens are positioned on this area having a top left corner and a width and size. Similarly windows are on that area with the top left corner of the window being their position and having a width and size down and to the right.

So move or resize a window on to that area you can use the SCREEN or SCREENVISIBLE functions together with the WINDOW function a little maths to determine where to place the window.

Keyboard Maestro will help you a little as you can select from the menu in the Manipulate a Window action. So for example, if you choose the Right column, you get:

image

The first entry, SCREENVISIBLE(Main,MidX) is the position of the middle of the main screen. It could also be written as:

  • SCREENVISIBLE(Main,Left)+SCREENVISIBLE(Main,Width)/2
  • SCREENVISIBLE(Main,Right)-SCREENVISIBLE(Main,Width)/2
  • (SCREENVISIBLE(Main,Left)+SCREENVISIBLE(Main,Right))/2
  • SCREENVISIBLE(Main,Left,50%)

Hopefully that is enough to get you started, though it probably doesn't really answer your more meta question of how to find the answer.

4 Likes

Thank you, @peternlewis, I greatly appreciate this detailed answer. It was insightful, and helped me to see how I misinterpreted this sentence "Coordinates are in absolute nominal resolution pixels relative to the top left corner of the main screen."

I learned things! You are a rock star! :slight_smile: I am particularly excited about the Option Key+Menu trick.

You also mentioned something I had tried, but did not work on my MacBook Pro 16". When I built a macro using the Action [Manipulate a Window] and set it to "Move and Resize" > "Right Column", the window went off the right-side of the screen.

But after posting this question, I rebooted my Mac for other reasons, and have just tried that macro again. It now works (of course). So this is also a reminder to me that when I'm experimenting, I need to periodically consider "wrong' behavior may be resolved with rebooting.

Thank you very much for your time and attention, I sincerely appreciate your help to better understand this tool.

3 Likes

Yes, the SCREENVISIBLE function, as you correctly stated, returns the visible section of the screen, excluding the menu bar and the dock. When used in conjunction with the "Right" parameter, it specifies the right edge of the visible area, not the right edge of the entire screen including the menu bar and dock.

Our goal is to align the right edge of the window with the right edge of the main screen, using SCREENVISIBLE(Main,Right), and it would indeed result in the window being partially off-screen, with its left edge aligned with the right edge of the visible area.

However, to achieve the desired behavior of aligning the right edge of the window with the right edge of the entire screen, you need to use the SCREEN function instead of SCREENVISIBLE. The SCREEN function returns the position or size of the entire screen, including the menu bar and dock. Using SCREEN(Main,Right) would provide the correct coordinates for aligning the window's right edge with the right edge of the main screen.

Therefore, the statement "SCREENVISIBLE(Main,Right) is the position of the Right edge of the Main screen in absolute nominal resolution pixeks relative to the top left corner of the main screen" is inaccurate. It should be corrected to "SCREENVISIBLE(Main,Right) is the position of the Right edge of the Visible area of the Main screen in absolute nominal resolution pixeks relative to the top left corner of the main screen."

Yes, that is correct (although for almost all users the two are the same since the dock is on the bottom of the screen and the menu is on the top of the screen, and so the right edge of the visible area is generally the same as the right edge of the entire screen.

Also note that you cannot generally move or resize a window outside the visible area on the screen (eg under the menu bar or the dock), so if the screen visible right edge is different to the screen right edge, you probably cannot resize your window to be on the right edge of the screen.