Now the ui elements I get :
static text 24 of window CapCut of application process CapCut
tell application "System Events"
get description of static text 24 of window "CapCut" of application process "CapCut"
end tell ----> "automationresInfo"
How do I get information about the level (white selected) on the image?
The hierarchy in AppleScript doesn’t always line up with the hierarchy in Accessibility Inspector.
In AppleScript, each level should provide a “UIElement” property that’s a catch-all/generic name for the other types of element (e.g. group, static text, etc) that are children of that level. So, for example, UI Element 4 may point to the same thing as static text 1 depending on how it’s laid out.
I’ve had the most success with drilling down through various levels of UI element to find the object I’m looking for using Script Debugger’s explorer. Then, it usually makes sense to use the more specific classes to refer to it in code.
So, something like:
static text 2 of UI element 4 of UI element 2 of UI element 3 of window 1
becomes
static text 2 of group 2 of scroll area 1 of group 1 of window 1
Sometimes there isn’t a more specific class, though, and you’re stuck with UI element.
I don’t have that particular application installed on my machine. It looks like it’s a popover, which are extra difficult to capture because they disappear easily.
Really, the only easy way is to iterate with Script Debugger in the background.
activate application "Capcut"
delay 3 -- Manually trigger popover
tell application "System Events"
tell process "Capcut"
return window 1
end tell
end tell
And iteratively build the reference, e.g.:
return scroll area 1 of window 1
Until you find what you’re looking for.
You could also look into UI Browser, which can directly capture this AppleScript Reference.
it’s not a popover. I just thought I found it, but it’s not. This one gets results
tell application "System Events"
get description of static text 28 of window "CapCut" of application process "CapCut"
end tell
It seems that every time I want to get the description of static text 28, I have to use static text (29 - 1) to get it. Because I click at {cursor} with the mouse, the number behind the static text obtained is 29, not 28, so I have to use 29 - 1 can be obtained. I think it shouldn’t be so troublesome. There should be other methods. I don’t know why.
But static text 29 and 28 are only in a hierarchical relationship. I don’t know how to get this description text directly through static text 29 instead of 29 - 1.
I’m not sure I completely understand what you mean. Accesibility Inspector may be misleading you depending on where you’re hovering.
Be aware that a static text will have a description property that probably doesn’t give any useful information beyond what its value will give.
(The application itself may have a description field which is completely different that the description property that AppleScript provides for UI elements.)
AFAIK, a static text can’t have any children; two static texts are never above/below each other same hierarchy.
Also note that static texts can sometimes be accessed from higher view levels as well as their direct parent. So,
static text 5 of window 1
may be the same object as
static text 1 of scroll area 1 of window 1
That’s why you’re usually best to hunt for any reference to the UI element you want, and then find the most specific “canonical” path.
I would give up on Accessibility Inspector & focus on figuring out how to address it through AppleScript.
If you’re able to access the information that you want by going to the previous static text (n - 1), then you may have figured it out as best as you can with AppleScript. You haven’t said how you’re determining n.
I think it’s a little too difficult for me to provide any further information without the application available.
If you’re clicking something with system events, though, remember that any changes within the window caused by the click may change the indices of the UI elements.
So e.g. static text 28 may refer to a different static text if something changes in the window because of the click.
The app is called capcut, if it’s convenient, you can download it. Because I use another app wooshy , as long as I move the cursor over, it can get the result directly, I don’t know how it does that.,