UI Scripting in AppleScript
Open the “Accessibility Inspector” app to try to determine each element
Example with some UI Scripting for Messages app to set the default send address:
tell application "Messages" to activate
delay 1
tell application "System Events"
tell process "Messages"
click menu item "Preferences…" of menu "Messages" of menu bar 1
click button "iMessage" of toolbar 1 of window 1
click radio button "Settings" of tab group 1 of group 1 of window 1
--open "Settings" tab of group 1 of window 1
set SendFromPopUp to pop up button 1 of tab group 1 of group 1 of window 1
click SendFromPopUp
click menu item "user@icloud.com" of menu of SendFromPopUp
click button 1 of window 1
end tell
end tell
Handy reference: https://n8henrie.com/2013/03/a-strategy-for-ui-scripting-in-applescript/