In AppleScript GUI scripting you could use class of UI elements it will return every class of UI element in target tell block.
In other words.
tell application "System Events" to tell application process "System Preferences"
set frontmost to true
class of UI elements
end tell
Will return {window, menu bar}
Next you could do
tell application "System Events" to tell application process "System Preferences"
set frontmost to true
tell window 1
class of UI elements
end tell
end tell
So what you are doing is… return class of UI elements to you find the target UI elements.
You could ask ex. tell buttons to its name but not all UI elements have names and instead
use missing value. You could then use index number ex. tell button 3 to click
Doing this could take time, and some UI elements needs to be clicked to reveal its UI element.
To understand it all takes practice and could become very complex. I still use Monterey on my machine so I do not have the issue
This example will click the red dot upper left corner of System Preferences window
tell application "System Events" to tell application process "System Preferences"
set frontmost to true
tell window 1
tell button 3 to click
end tell
end tell
If the name of button is missing value, we could make name and set a integer to it.
To make the code easier to read and understand.
tell application "System Events" to tell application process "System Preferences"
set frontmost to true
tell window 1
set quitWindow to 3
tell button quitWindow to click
end tell
end tell
Here is example of using ASObjC to build a dictionary of every checkbox in General pane.
This script have been running on Monterey 12.6.2 The checkbox return integer value of boolean. So I have converted it to boolean value and set missing value to a string. In this case the missing value was “Auto”
use framework "Foundation"
use scripting additions
tell application "System Preferences"
reveal pane "General"
delay 0.2
end tell
set theDict to current application's NSMutableDictionary's dictionary()
tell application "System Events" to tell application process "System Preferences"
set frontmost to true
tell window 1
tell every checkbox to set {theNames, theValues} to {its name, its value}
repeat with i from 1 to count theValues
if (item i of theNames) contains missing value then
set item i of theNames to "Auto"
end if
(theDict's setObject:((item i of theValues) as boolean) forKey:(item i of theNames))
end repeat
-- quit the window
tell button 2 to click
end tell
end tell
return theDict as record