【问题标题】:Applescript getting elementsApplescript 获取元素
【发布时间】:2019-07-09 01:09:02
【问题描述】:

This SO answer 进一步指出了我在新 MacBook Retina 上编写屏幕分辨率更改的脚本。我被困在这里:

我可以使用此脚本到达此窗格:

tell application "System Preferences"
    activate
    set the current pane to pane id "com.apple.preference.displays"
    reveal anchor "displaysDisplayTab" of current pane
    get elements of current pane
    tell application "System Events"

    end tell
    --get the name of every anchor of current pane
end tell

但是如果此窗格内容,如何知道如何选择位?例如,如何参考“缩放”单选按钮并选择 5 种可能的分辨率之一?谢谢

【问题讨论】:

  • 我没有配备 Retina 显示屏的 Mac,但单选按钮是 tell application "System Events" to tell process "System Preferences" to radio button 4 of tab group 1 of window 1。您可以使用UI elements of 缩小元素范围。通常可以使用clickperform action "AXPress" of 选择它们。
  • UI Browser 对查找元素的路径非常有帮助。它是 55 美元,但可以免费试用。

标签: macos applescript


【解决方案1】:

我发现这段 AppleScript 显然检索了 Window 中可用的每个 UI 元素:

tell application "System Events"
tell process "Process Name"
set visible to true
return every UI element of front window
return name of every UI element of front window
end tell
end tell

(还没有测试自己。找到here。)

【讨论】:

    【解决方案2】:

    Image to tell you what radio button number you need for property: _MS on line 7

    use sys : application "System Events"
    use prefs : application "System Preferences"
    
    property prefsUI : a reference to process "System Preferences"
    property _W : a reference to windows of prefsUI
    property _DD : a reference to radio button "Default for display" of radio group 1 of tab group 1 of _W
    property _SD : a reference to radio button "Scaled" of radio group 1 of tab group 1 of _W
    property _MS : a reference to radio button 4 of radio group 1 of group 2 of tab group 1 of _W
    
    property pane : "com.apple.preference.displays"
    property anchor : "displaysDisplayTab"
    property tab : anchor (my anchor) of pane id (my pane)
    
    set defaultDisplay to null
    if tab ≠ (reveal tab) then return null
    
    tell _DD to if exists then set defaultDisplay to its value as boolean
    
    if defaultDisplay is false then
        click _DD
    else
        click _SD
        click _MS
    end if
    
    quit prefs
    

    脚本会在默认分辨率和“最大空间”分辨率之间交替,具体取决于当前处于活动状态。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多