Locating a button by its help attribute

Hello all - I’m trying to get a reference to a button by finding it thru it’s “help” attribute. This is the text that pops up if you hold the mouse (but not click) over a button, etc.


set badButton to every button of first scroll area of every window whose help is "Increase Electrons"

The app has a very poor UI implementation, as the window indexes are constantly changing. Additionally, the button is not named - this is why I’m searching for the button by its “help” attribute.

The code above returns:
{{}, {}, {}, {button 4 of scroll area 1 of window 4 of application process “MyApp” of application “System Events”}, {}, {}, {}, {}}
so it does find the button thruout all the windows in the app, which is good.

How do I then refer to that button in the list, so for example, I can act upon it like increment it?

Note that the location of the button in the index may change, in the above example it happens to be at location #4 in the list, but that may change.

Any help greatly appreciated!

Hi,

you need probably a repeat loop like


tell application "System Events"
	tell process "myApp"
		set badButton to every button of first scroll area of every window whose help is "Increase Electrons"
		set theButton to my getButton(badButton)
		if theButton is false then display dialog "not found"
	end tell
end tell

on getButton(W)
	repeat with oneWindow in W
		repeat with oneButton in oneWindow
			if oneButton is not {} then return contents of oneButton
		end repeat
	end repeat
	return false
end getButton

Hi StefanK - that works wonderfully. Thank you! :slight_smile: