Henri Lapierre Henri Lapierre - 2 months ago 12
AppleScript Question

Getting MenuItem DisplayValue with Applescript

Using Applescript, I would like to retrieve all the display value of the menu items of the Help menu.

So far I have:

#!/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


which returns:

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


would there be a way to only retrieve the display value?

enter image description here

In my case I would like to outout:

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

Answer

Most likely not the best solution, but the following seems to be working:

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

Let me know if you know a better way

Comments