使用Applescript获取MenuItem DisplayValue

时间:2016-08-29 19:14:35

标签: applescript ui-automation

使用Applescript,我想检索“帮助”菜单中菜单项的所有显示值

到目前为止,我有:

#!/usr/bin/osascript
on run {appName, myCmd}
    tell application "System Events" to tell process "Chrome"
        set frontmost to true
        set myMenu to menu bar item "Help" of menu bar 1
        set allUIElements to entire contents of myMenu
        repeat with anElement in allUIElements
            log name of anElement
        end repeat
    end tell
end run

返回:

name of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of static text Search of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of text field Search of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of row 1 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of UI element 1 of row 1 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of static text 1 of UI element 1 of row 1 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of UI element 2 of row 1 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of image 1 of UI element 2 of row 1 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of static text 1 of UI element 2 of row 1 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of row 2 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of UI element Menu Items of row 2 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of static text Menu Items of UI element Menu Items of row 2 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of UI element Import Bookmarks and Settings… of row 2 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of image 1 of UI element Import Bookmarks and Settings… of row 2 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of static text Import Bookmarks and Settings… of UI element Import Bookmarks and Settings… of row 2 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of row 3 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of UI element 1 of row 3 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of UI element 2 of row 3 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of row 4 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of row 5 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of row 6 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of row 7 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of row 8 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of row 9 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of row 10 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of row 11 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of row 12 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of row 13 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of row 14 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of row 15 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of row 16 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of row 17 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of row 18 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of row 19 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of row 20 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of row 21 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of column 1 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome
name of column 2 of table 1 of menu item 1 of menu Help of menu bar item Help of menu bar 1 of application process Google Chrome

有没有办法只检索显示值?

enter image description here

就我而言,我想要外出:

Import Bookmark and Set ...
Always Show Bookmarks Bar
Bookmark Manager
[...]
Customize the Finder tool..
Set up parental controls
Show all Help Topics

1 个答案:

答案 0 :(得分:0)

最有可能不是最佳解决方案,但以下似乎有效:

repeat with anElement in allUIElements
    set className to class of anElement
    set displayValue to name of anElement
    if (className as string) is equal to "static text" then
        if (displayValue as string) is not equal to "missing value" then
            log displayValue
        end if
    end if
end repeat

如果您知道更好的方式,请告诉我