Create Tell Block for UI Interaction - "UI Browser Lite"

Hiya. Without being able to access your particular software, it's hard to know if it's an issue with the macro's function or the scriptability of the app you're working with. I think your notion that the software isn't set up to with scripting in mind is likely to be the stumbling block, but it's hard to know.

In terms of you figuring it out yourself, you can capture the output of the Get Info for UI Element Under Mouse action and see if the element or info you're trying to target is contained within it. If it is, you might be able to parse it out as part of the Parse and Generate Tell Blocks script action.

Fortunately, Keyboard Maestro has plenty of other problem-solving tools, and this forum is blessed with a lot of clever people who like a challenge, so if you do run into issues, there's usually an elegant (or inelegant) alternative solution to AppleScript.

Thanks so much for your reply.

Again it looks like my skills are by far not sufficient to get what you are writing about because I couldn’t find the “Get Info for UI Element Under Mouse" action.

Inspired by your answer I tried different things. The element I try to click is a text field but the click doesn’t happen since it doesn’t show the value selected within the field. like it does with a manual click action.

click text field 33 of window "Untitled"

If I change the script to use “select” instead of “click” it gives the following result:

text field 33 of window Untitled of application process [app name]

But that’s just meant as a feedback. Please don’t invest any more effort. I can find my workarounds for cases like this.

Thanks again!

I'm not sure I understand what you mean by this. Could you elaborate? Perhaps with screenshots?

Thanks again and apologies, I was searching for this action within KM. :roll_eyes:

The first field is unselected and the second one after a manual click to enter or change the value.

As you mentioned in your macro, it uses a click when activated which I experienced in all other cases. But if I place my mouse over this kind of text fields it stays like field 1 in the screenshot above.

How do you know it is text field 33? Does the click work for text fields with different numbers? This wouldn't be the first time that a developer has masked the actual field with another to "interesting" effect...

It looks like the UI has a very flat hierarchy. Start in Script Editor with

tell application "System Events"
	tell process "myApp" -- replace myApp with your app's name
		properties of text field 33 of window "Untitled"
	end tell
end tell

That'll get you a list of properties, including value that you can compare to the contents of your fields and position that you can match up with KM's Mouse Display coordinates. You can then try other numbers to get a feel for the field layout.

If the field has a unique value you should be able to:

tell application "System Events"
	tell process "myApp" -- your app's name here
		every text field of "Untitled" whose value is "myUniqueValue" -- your unique value here
	end tell
end tell

That might help narrow down your target.

1 Like

I wonder if you could try something other than click here? For instance:

tell application "System Events"
    tell process "TargetApplication"
        -- Set focus directly on the text field
        set value of attribute "AXFocused" of text field 33 of window 1 to true
    end tell
end tell

(Example element tree; adjust as needed)

2 Likes

Thanks so much @Nige_S. I’ll check it tomorrow and get back to you.

The information about the number of the text field is provided in @noisneil ‘s macro.

Thanks a lot @noisneil and again, I'll continue tomorrow because it’s getting late here. :wink:

UPDATE 2026-07-09 (because I’m not allowed to answer again separately)

Thanks so much @noisneil for this script which did the trick. I tested it with different fields and it works great!

Thanks again for your help, much appreciated!

I tried your scripts but the result has mostly “missing values” except position, size, type etc..

But I tried the adapted script from @noisneil which did the trick.

Thanks again for your help, much appreciated!

1 Like

Great! I've updated the macro so that it focuses rather than clicks if the target element is a field.

2 Likes

That means the dev's haven't included values for those properties -- missing value is an object that's returned in those situations, not a textual representation of "nothing to see here". Of course, the app framework may not allow (or make it easy) to include such -- is this an Electron app?

Nice!

2 Likes

Thanks and no, it is not an Electron app. I’m not allowed to name it here because as I mentioned it is for internal use only. It’s just a tool for a handful of people around the world so it was therefore likely developed with very little effort and a minimal budget.

Thanks anyway for your kind help as always.

Wow, that’s amazing.

Thanks again for your help and support. :blush:

1 Like

Hello Neil (@noisneil) I just saw your change to the Macro…

While I think it is a great enhancement to get an element focused, I think it’s important that this has to be an option as well as the ability to click it.

Is it possible for you to bring back the click functionality and keep the new functionality to focus an element?

This would be great. Thanks.

Greetings from Germany :germany:

Tobias

Focus only replaces click for fields. For all other elements it defaults to click. This makes sense to me as scripting a field click doesn't appear to do anything useful.

2 Likes

Okay … for editable fields whose contain textual or digit values as input that might be true. Good catch on that.

But what’s about catching up on fields that are static whose also can deliver a lot of information (Of course if a developer has set them up correctly, so they offer the needed information)? Such fields act like a button in many cases and often a click might also change the GUI because their functionality is like the modern NavigationLink.

Focusing them first to get information about what they are for and then deciding whether to click on it or not is also something really important step in GUI scripting.

If your Macro already supports this behavior then feel free to scratch my feature request. But if not then it might be worth integrating it.

Good work as always, though.

Greetings from Germany :germany:

Tobias

Can you give me a specific example?

Aside: One thing I've noticed is that combo-boxes (e.g. the font size field/dropdown in TextEdit) don't react to click or focus via AppleScript. Not sure what to do about that.

I can't get the text field part to select, short of passing the position back to KM and clicking from there -- so this will double-click the field assuming TextEdit is frontmost:

AppleScript
tell application "System Events"
	tell process "TextEdit"
		set thePos to (get position of combo box 1 of toolbar 1 of window 1)
		set theX to (item 1 of thePos) + 5
		set theY to (item 2 of thePos) + 5
	end tell
end tell

tell application "Keyboard Maestro Engine" to do script "<dict>
		<key>Action</key>
		<string>MoveAndClick</string>
		<key>Button</key>
		<integer>0</integer>
		<key>ClickCount</key>
		<integer>2</integer>
		<key>DisplayMatches</key>
		<false/>
		<key>DragHorizontalPosition</key>
		<string>0</string>
		<key>DragVerticalPosition</key>
		<string>0</string>
		<key>Fuzz</key>
		<integer>15</integer>
		<key>HorizontalPositionExpression</key>
		<string>" & theX & "</string>
		<key>MacroActionType</key>
		<string>MouseMoveAndClick</string>
		<key>Modifiers</key>
		<integer>0</integer>
		<key>MouseDrag</key>
		<string>None</string>
		<key>Relative</key>
		<string>Absolute</string>
		<key>RelativeCorner</key>
		<string>TopLeft</string>
		<key>RestoreMouseLocation</key>
		<false/>
		<key>VerticalPositionExpression</key>
		<string>" & theY & "</string>
	</dict>
"

The dropdown is easier, it's a button element of the combo box:

tell application "System Events"
	tell process "TextEdit"
		click button 1 of combo box 1 of toolbar 1 of window 1
	end tell
end tell
1 Like

Yeah, sorry, I meant specifically fields in combo boxes.

I've updated the macro to include an optional double-click (which is defaulted to enabled for combo box fields, because why not?).

2 Likes