How do I access this GUI element? The path/code suggested by UI browser fails

I want to check for the progress bar in Messages main window:

UI Browser lists the path to this element like this (sorry for the screen shot, couldn’t copy the text):

I tried this code:


tell application "System Events"
	tell process "Messages"
		if exists UI element 3 of group 1 of group 1 of window 1 then

but it can’t find UI element 3.

I notice UI element 3 is within parenthesis in the UI Browser while the other elements’ type is outside. Is that the problem? How do I check for this element?

Thank you.

I’m not a facetime user so I don’t have anything to say on that aspect but the element in question must exist when the script runs. It could be that the progress bar only exists when it’s busy progressing.

It is Messages.app (I know it says Facetime in the image). The progress bar is there because the message is stuck on the transfer.

I think I have hit some rate limit, both on iMessages as well as SMSs. That is the reason for my question: I want to detect this progress bar and if it is there for more than a few seconds I want to break (in my situation the progress bar is there for hours).

I think you can emulate this by sending an SMS (not iMessage) when your phone is in flight mode. In that situation I think this progress bar will be there for at least several minutes.

What happens if you use a line like this:

UI elements of group 1 of group 1 of window 1

It should return a list that would presumably include UI element 3.

{group 1 of group 1 of group 1 of window "[phonenumber]" of application process "Messages" of application "System Events"}

I also tried adding/removing one level of group:


	get every UI element of group 1 of group 1 of group 1 of window 1 of process "Messages"
		--> {group 1 of group 1 of group 1 of group 1 of window "[phonenumber]" of application process "Messages"}
	get every UI element of group 1 of window 1 of process "Messages"
		--> {group 1 of group 1 of window "[phonenumber]" of application process "Messages"}

So just more levels of groups.

You can emulate the behaviour I see by turning off the computer’s network and then try to send an SMS/iMessage. Now the progress bar will appear. How do I detect that?

Try this. You won’t believe me if it works…

tell application "System Events"
	tell process "Messages"
		repeat
			if exists UI element 3 of group 2 of group 2 of group 1 of group 1 of group 1 of group 1 of group 1 of group 1 of window 1 then
				beep
				delay 2
			else
				say "Done!"
				exit repeat
			end if
		end repeat
	end tell
end tell

It will keep beeping while the Progress Bar exists. Then it will say ‘Done’ when it goes away

or even shorter…

tell application "System Events" to tell process "Messages"
	repeat while exists UI element 3 of group 2 of group 2 of group 1 of group 1 of group 1 of group 1 of group 1 of group 1 of window 1
		beep
		delay 2
	end repeat
	say "Done!"
end tell
1 Like

How the 㡪:gun::facepunch::anchor::snake::crossed_swords::dagger::hocho::zap::star2::cloud_with_rain:#$@&%*!:bomb:꩜ #⃣:skull_and_crossbones: did you figure that out? Why did UI Browser return a completely different path??

“UI Browser” is old.
Apple’s own “Accessibility Inspector” also gives bad results

Apple, as of late, has quite a few programs that don’t work properly with GUI scripting. Sometimes I have to keep looping thru groups inside groups till it finally finds the item I’m looking for. I have a script that will search for these things for me recursively.

Also it really helps to use Script Debugger.

Just so you know, another oddity of “Messages” is that I can’t get to the scroll bars using GUI scripting.

Something else to try would be recording the events (clicks, etc) with Automator’s Watch Me Do action and see how it is declaring the UI elements. I haven’t tried it with Messages, but if it successfully plays back the recorded events, there should be valid UI element descriptions you can use.

To use Watch Me Do, create a new Automator workflow and press the record button. The action will automatically be added to the workflow and the various things you do will start being recorded, so navigate to the desired UI element(s), and then stop the recording. In the action’s user interface, a list of events will be shown that can be copied (using the main Edit menu) and pasted in the Script Editor. Each of these events will be a script that consists of a doWithTimeout handler and a few statements that set it up - the item of interest would be the string describing the UI element.

Nope!

It only shows mouse clicked, That’s it. No info as to where in the App or any UI Element.

There are more oddities with Messages support for AppleScript:

  1. If I launch Messages and executes this (simplified) script:
	set chatList to get chats
	log (count of chatList)

I get one value (about 200). But if I scroll all the way down to the bottom of the chat list, and let it reload several times I get another value (about 500).

  1. If I delete a chat (not just a message but the whole chat in the left pane of the main window), the phonenumber of the deleted chat is still returned by the script above, as it still existed.

It is almost as you should run an old version of MacOS virtualized if you want to script Messages?