首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Applescript获取元素

Applescript获取元素
EN

Stack Overflow用户
提问于 2012-07-29 18:21:31
回答 2查看 6.5K关注 0票数 2

This SO answer在新的MacBook视网膜上编写了改变屏幕分辨率的脚本,进一步向我指出了这一点。我被困在这里了:

我可以使用以下脚本进入此窗格:

代码语言:javascript
复制
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

但如何知道如何选择位,如果此窗格内容?例如,如何引用"Scale“单选按钮,并从5种可能的分辨率中选择一种?谢谢

EN

回答 2

Stack Overflow用户

发布于 2013-05-23 18:34:35

我发现了这段AppleScript,它可以检索窗口中所有可用的UI元素:

代码语言:javascript
复制
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。)

票数 8
EN

Stack Overflow用户

发布于 2019-07-09 01:09:02

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

代码语言:javascript
复制
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

脚本根据当前处于活动状态的分辨率在默认分辨率和“最大空间”分辨率之间交替。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11708459

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档