Blind user seeking help on window condition variable

I recently figured out how to set a variable to the size of the front window and successfully used it within an If Then Else macro as a condition for a Move and Click mouse action. I’ve come to realize that the window in question can actually be one of many fixed sizes (some 16 potential sizes). The window is not resizable, per se. If certain elements are selected, it dynamically changes the size of the window and it has no resizing controls. Most importantly, if the window is 990 points wide, nothing needs to be done except a click to yield the final result of the mouse click on a particular screen coordinate. If the window is 664 points wide, a simple f1 keystroke displays the necessary elements to bring the window to 990 points wide and the click is performed. If the window is 649 points wide, a strategic mouse click gets it to 664 points and then the f1 keystroke and so on.

So, what I’m trying to figure out is how to set a variable to the front window’s width rather than its size because, with window size, I have so many potentials whereas, with width, there are only 3 potential widths. I’ve poked around and did some searching but I haven’t seen anything that seemed to apply.

As mentioned in the topic, I’m a blind user and new to this forum. Navigating it is still new to me so I hope I can navigate my way back to check for responses. I know other blind users who seem to have negotiated the forum without too much difficulty so we’ll see… so to speak :wink:

Thanks for any help.

Slau

Slau, your post is amazing. It is better than most users who can see.

I hope you can read and understand this OK.
Please feel free to ask any questions, and even attach a zipped audio file if that makes things easier for you. To attach a file, just drag it into the window pane where you are writing your post.

I have added the text "[link]" to the hyperlinks I have provided below.
Hopefully that will allow you to identify and click on these links.
If there is a better method of providing the links for you, please let us know.

It is very easy to get the front window width using the WINDOW function (KM Wiki) [link]. This function includes a parameter for the width of the window.

Here is an example KM Action:
This will set the Keyboard Maestro Variable "Front Window Width" to the width of the frontmost window:

It uses the KM Action "Set Variable to Calculation [link]", with the Action's fields set as follows:

  • Set variable: "Front Window Width"
  • to: "WINDOW(0,Width)"

Note that these are entered into the Action without quotes.

Next is an image of this Action for reference to other readers:

Again, please feel free to ask any questions.

Hi JMichaelTX,

Thanks so much for the response. This is great—your explanation seems very straight-forward and easy to understand. I think this approach will certainly simplify the path toward my goal. Thanks also for the links. screen readers do easily detect hyperlinks within text. The problem is when images are treated as links when they are without alt tags. Then the screen reader reports “Image, link” with no way to know what that image is and where it might point. As an aside, I’m glad to have learned that email notifications seem to be the default if one creates a topic which makes it super convenient for tracking responses. So glad I finally joined the forum.

I’ll give your suggestions a try soon. Cheers!

Slau

Hi JMichaelTX,

OK, so I’ve incorporated the Set Variable to Calculation action with the WINDOW(0,width) function and it has greatly simplified my If Then Else process. Now I have a question related to the Front Window Width variable.

So, when I previously used the Set Variable to Text action with %WindowSize%1% function(?), I found that I had to use %Delete% as a final variable action or else I’d get multiple values within the text of the variable. I’ve noticed that, upon using the new macro with several different window sizes, I’m getting multiple values in the calculation. I mean, I’m not exactly sure what’s going on visually but it appears that the calculation has a series of right right arrow followed by number. Is it advisable for me to end the string of actions with some sort of “delete” action? My gut tells me to use an action like Set “Front Window width” to text where the value is %Delete% but I’m not at all sure if that’ll truly work. Can you shed some light on this question whenever you have a moment? Much appreciated!

Slau

WindowSize is a KM Token (KM Wiki), which works kinda like a function in that the token returns the value of something as indicated by the token name. Generally, you can use Tokens in a "Set Variable to Text", but NOT in a "Set Variable to Calculation" Action.

Functions generally can be used ONLY in an KM Action field that is a "calculation" or "numeric" field, like in the "Set Variable to Calculation".

In this case, the WindowSize token returns two values, separated by a comma:
width,height

For example, this KM Action:
Set Variable ‘Front Window Size’ to Text
%WindowSize%1%

might return:
810,900

Here is an image of this Action for the benefit of other readers:

Every time the Macro executes, it will set the indicated KM Variable to the window size of the frontmost window. It does NOT add more values. It replaces the current value of the KM Variable with that set by the Action.

In general, you do NOT need to use a "Set Variable to Text" with "%Delete%" as the Action value. You need do this ONLY if you wish to remove that Variable from the KM Variable list shown in the KM app Preferences, Variables pane.

If you would like to tell us all of the steps of the workflow you want to automate, we could mostly provide a more complete example Macro.
IOW, just write down the steps you would normally take to manually accomplish your workflow.

I hope this helps. Please feel free to provide any feedback that will help us better respond to your questions.

May I ask one question? Do you have anyone helping you that can see the computer screen? If so, I'm thinking that including images might help them help you.

Hi JM,

Thanks for the clarification. It seemed as though, with the Set Variable to Calculation, it worked once and never again. IOW, it worked the first time I tried it with a certain set of actions but, eventually, as I added more conditions and actions, it seemed to stop working. I guess I thought the variable somehow needed to be “refreshed” or “reset.” I now understand that it’s a dynamically changing value whenever it is called.

At this point, I have a few layers of conditions and actions based on the 3 variations of possible window sizes within the application. I have 2 different macros handle their series of actions in a slightly different manner but, most importantly, they seem to be working flawlessly right now. breathes a sigh of relief

I must say, being a musician with no programming background, some of this is daunting. as with most things, once you’ve done it, things start to make more sense. That said, given the enormous amount of time I’ve been spending, trying to figure out how to make things work, reading, searching, testing, etc., I sometimes feel like I’d be better off paying somebody to assemble macros. If such a thing exists, I’d probably avail myself of such services :slight_smile: For now, I’ll muddle through.

BTW, I generally don’t have much sighted assistance at my studio unless I arrange for somebody to sit with me to grab screen coordinates and verify on screen changes and behaviors. Perhaps the biggest challenge I (and other blind users) face is when a developer creates an application (especially cross-platform) and writes it in such a way that no UI elements are exposed to the OS. In cases like this, VoiceOver (the built-in screen reader in Mac OS) sees absolutely nothing. In cases like that, Keyboard Maestro sometimes means the difference between being able to use the application to at least some degree or not at all. In the cases where UI elements are not exposed, it’s especially challenging with things like radio buttons and checkboxes where you don’t know the status. It’s one thing to move and click a mouse at that location but, not knowing the state of such controls makes it very much like shooting in the dark.

Anyway, I’m veering off topic. I’ll save my “search for image” questions for a different topic :wink:

Thanks again!

slau

OK. It sounds like all of your questions have been answered.

We often help people here by providing complete macros.

I, for one, would be more than willing to help you pro bono, and write, edit, or generally assist you in developing Keyboard Maestro Macros. I’m pretty sure there are several other folks here that would be willing to help. We do have several musicians who hang out here, so they might be available to help you with music-specific questions.

If you need help with anything sensitive, please feel free to send me a Private Message (PM). Link: Send a PM to JMichaelTX

1 Like

Thanks so very much. I truly appreciate it. Cheers!