How to Iterate Dynamic Button Groups to Find a Specific Button?

I’m a novice scripter trying to iterate a button group to find one that has button inside that is true.

My goals are -

  1. Locate a specific nested group whose button 1 has a true value.
  2. Click button 4 inside this group.

I’ve tried to adapt an example I saw on the forum, but after several hours and some success, I am stuck. Can anyone pls help? I’ll document as best I can.

CODE

tell application "System Events"
	tell process "iZotope RX 10"
		set frontmost to true
		tell window 1
			tell group 2
				set markerList to (description of every button of every UI element of every group)
				repeat with markerGroup from 1 to (count markerList)
					set candidateGroup to (a reference to markerGroup)
					if (value of button 1 of candidateGroup is true) then set correctGroup to candidateGroup
				end repeat
				click button 1 of candidateGroup
				return
			end tell
		end tell
	end tell
end tell

Note: The Window is “window 1”, as RX promotes this floating window to “window 1” when it opens.

UI BROWSER SCREENSHOT AND BUTTON MAP

A screenshot from UI Browser pointing to (in this case) the desired button:

HIERARCHY LEVELS

  1. window 1: The floating window I’m targeting. These elements are static.
  2. group 2: The group of all markers. The number of them is dynamic (as the user can create and delete markers).
  3. The individual UI elements for a specific marker. These elements are static.

I hope this enough information, and thank you for any help possible.

Bill

It would help if you describe the Application you are using and how to get to the windows you want to script. I downloaded IZotope RX 10 Advanced Audio Editor. Is this the correct app?

I’ve figured some things out. If there are more than 1 marker which is checked, do you wish to click on button 4 for each one?

if more than one marker is checked, clicking on button 4 will turn that field into edit mode, and only the last checked marker will be selected.

Here is what I have so far…

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "System Events"
	tell process "iZotope RX 10"
		set frontmost to true
		set myWin to window "Markers and Regions"
		set myMarkers to groups of group 2 of myWin
		repeat with aMarker in myMarkers
			set aMarker to contents of aMarker
			if (value of button 1 of aMarker as integer) = 1 then
				click button 4 of aMarker
			end if
		end repeat
	end tell
end tell

or you can use a “whose” clause to get only those markers that are checked like so…

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "System Events"
	tell process "iZotope RX 10"
		set frontmost to true
		set myWin to window "Markers and Regions"
		set myMarkers to groups of group 2 of myWin whose value of button 1 = 1.0
		repeat with aMarker in myMarkers
			set aMarker to contents of aMarker
			click button 4 of aMarker
		end repeat
	end tell
end tell
1 Like

I am absolutely stunned - that’s brilliant, yes - it’s perfect. And the code is so simple! Thank you so much for your kindness and expertise.

EDIT: I used both scripts - and learn a lot. Thanks again!

After you click on Button 4, what are you doing? Are you editing the name?
If you want to edit the name you don’t need to click but can change the value directly.
Like so…

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "System Events"
	tell process "iZotope RX 10"
		set frontmost to true
		set myWin to window "Markers and Regions"
		set myMarkers to groups of group 2 of myWin whose value of button 1 = 1.0
		repeat with i from 1 to count myMarkers
			set aMarker to item i of myMarkers
			set value of button 4 of aMarker to "Section " & i
		end repeat
	end tell
end tell

Here is a version that will test if frontmost changes and bring the App frontmost to continue.

tell application "System Events"
	tell process "iZotope RX 10"
		if not frontmost then set frontmost to true
		try
			set myWin to window "Markers and Regions"
		on error
			return
		end try
		set myMarkers to groups of group 2 of myWin --whose value of button 1 = 1.0
		set i to 1
		repeat until i > (count myMarkers) --aMarker in myMarkers
			set aMarker to item i of myMarkers
			try
				set ma to description of aMarker
				set ma to text 10 thru -1 of ma
				set value of button 4 of aMarker to "Section " & ma
				set value of button 8 of aMarker to "Comments " & ma
				set i to i + 1
			on error
				beep 1
				if not frontmost then set frontmost to true
				delay 1
			end try
		end repeat
	end tell
end tell
1 Like

You are amazing…thank you again. My code runs much better with the direct change, thank you.

I’m creating and then automatically renaming the bookmarks with a string. It all works now!

If you’re willing to help me with a few more questions, I’m happy to get you a proper license for RX.

No problem. I have the sample version now.
I’m more than willing to help.

1 Like

Here’s a puzzler…I’m trying to directly change the value of the playhead, like you showed me in your third script.

I’ve re-worked all my scripts to change things directly like that—it’s an incredible improvement. (I was remote-controlling the mouse, previously.) But the playhead time field isn’t a button…it’s a bunch of static text elements. And when you click on any of them, a text field magically appears.

Do you have any idea how I could access that underlying text field? (Thank you again.)

I can’t see what window you are targeting in the picture. UI Browser is covering the target window.

Is it the main window?

1 Like

Sorry about that - yes, it’s the main window.

I’m having a difficult time in scripting to get the text edit field to appear. It doesn’t exist until you click on the “Time” text. It will disappear if the program looses focus. I haven’t found a way to script the click that works

1 Like

Thank you Robert, once yet again - once I knew (based on your comment) that I couldn’t click in that field, I was able to look elsewhere - and found a solution whereby I could move the playhead by setting the Selection Start field to the desired playhead position, and then setting the Selection Length to zero. :tada:

Could I ask another question, pls? I’m trying to directly change the name of a History item via AppleScript. The UI element is a radio button, and the Title is the name of the history item.

A user changes the name by double-clicking on radio button title. But I don’t think it’s possible to double-click with AppleScript?

In my usage of iZotope RX, there is a floating window (not pictured in the screenshot below) on top of the History panel, so I can’t automate moving the mouse and calling a library to double-click…because that would click on the floating window. :crazy_face:

Can you think of a way around this? Thank you.

** EDIT ** I’m having the same issue as with the other field. Text Field won’t appear by any scripting means.

I am now playing around with “cliclick” from this website.
https://github.com/BlueM/cliclick/releases

Yay!
I got it to work.
Check this out…

on run
	local myWin, myMarkers, aMarker, mname, mcomment, i, j
	tell application "System Events" to tell application process "iZotope RX 10"
		if not frontmost then
			set frontmost to true
			delay 0.1
		end if
		try
			set myWin to window 1
		on error
			return
		end try
		set myGroup to group 1 of myWin whose description is "Undo Panel"
		set myPos to position of radio button 1 of myGroup
		set myPos to {10 + (item 1 of myPos), 7 + (item 2 of myPos)}
		do shell script "/usr/local/bin/cliclick  dc:" & (item 1 of myPos) & "," & (item 2 of myPos)
		delay 0.2
		if exists text field 1 of myWin then
			set value of text field 1 of myWin to "Beginning State"
		end if
		delay 0.2
		key code 36 -- return key
	end tell
end run

I shall now be able to get the time field to work also.
Thank you “cliclick”.

1 Like

Here is the script to modify the time field…

on run
	local myWin, myMarkers, aMarker, mname, mcomment, i, j
	tell application "System Events" to tell application process "iZotope RX 10"
		if not frontmost then
			set frontmost to true
			delay 0.1
		end if
		try
			set myWin to window 1
		on error
			return
		end try
		set myGroup to group 1 of group 1 of group 3 of myWin
		set mypos to position of static text 4 of myGroup
		--set mypos to {16 + (item 1 of mypos), 6 + (item 2 of mypos)}
		do shell script "/usr/local/bin/cliclick  dc:" & (item 1 of mypos) & "," & (item 2 of mypos)
		delay 0.2
		repeat 10 times
			if exists text field 1 of myWin then
				set value of text field 1 of myWin to "00:00:00.000"
				delay 0.2
				key code 36 -- return key
				exit repeat
			end if
			delay 0.2
		end repeat
	end tell
end run

** EDIT ** - i changed the line

set mypos to {16 + (item 1 of mypos), 6 + (item 2 of mypos)}
I got the x,y cordintaes backwards
** EDIT 2** - actually since i chose the 4th text item in the time, I don’t need to add pixel counts to get to the centers, so you can just comment out that line like I didi above

1 Like

Once again…amazing!!! Thank you! I installed clicclick and everything was PERFECT. :rainbow:

Could I ask you another question, please? I’ve spent a week on this one, and can’t seem to get it. Hope you had a nice Thanksgiving. :slight_smile:

-- Open the RX's Export dialog box, and the macOS save dialog box.
tell application "System Events"
	tell process "iZotope RX 10"
		set frontmost to true
		click menu item "Export..." of menu 1 of menu bar item "File" of menu bar 1
		delay 0.5
		-- Click the OK button in the Export dialog box. This produces the standard macOS Save dialog.
		click button 2 of group 1 of group 1 of window 1
		delay 0.5
		
		-- Bring up the path selection dialog box.
		key code 5 using {command down, shift down}
		delay 1		
		keystroke "~/Documents/"		
		delay 0.5	
		keystroke return		
		delay 1
		set value of text field 1 of window 1 to "Ferrets"		
		delay 0.5	
		set bemButton to a reference to button 3 of window 1
		tell bemButton
			set focused to true
			click		
		end tell	
	end tell
end tell

I can’t work on it anymore as my trial license has expired.
Do you know how to reset it?

I tried un-installing it and reinstalling it. No Luck

1 Like

Hi Robert,

The trial cannot be renewed.

Please contact me via (Deep Purple guitarist) Steve Morse’s website via the Contact Page (scroll to the bottom). I will send you a commercial license for RX Elements. (And an autographed pick if you’re a fan.) Thank you.