You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何获取选中UI元素信息?AppleScript中UI元素识别与活动元素读取

AppleScript中UI元素的识别与信息读取

定位并操作UI元素

在AppleScript中,你可以通过层级路径精准定位UI元素并执行操作,比如你提供的点击示例:

click item 1 of text field 1 of sheet 1 of window 1 of application process "Umsatz" of application "System Events"

读取活动UI元素的信息

当然可以读取活动UI元素的信息。利用System Events,你能获取当前处于活动状态(或聚焦)的UI元素的各类属性,比如名称、类型、当前值等。

以下是一个实用示例,用于获取当前活动UI元素的关键信息:

tell application "System Events"
    set frontProcess to first application process whose frontmost is true
    set activeElement to first UI element of front window of frontProcess where it is focused
    -- 提取元素属性
    set elemName to name of activeElement
    set elemClass to class of activeElement
    set elemValue to value of activeElement
    -- 展示获取到的信息
    display dialog "元素名称: " & elemName & linefeed & "元素类型: " & elemClass & linefeed & "元素值: " & elemValue
end tell

另外,你可以使用系统自带的**辅助功能检查器(Accessibility Inspector)**来可视化查看UI元素的层级结构和所有属性,这会极大帮助你编写更精准的AppleScript代码。(注:你提供的截图展示了一个活动UI元素,借助检查器可以直观分析这类元素的属性)

内容的提问来源于stack exchange,提问作者Gerhard Uhlhorn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.23 15:24:09