Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a list of menu items with Applescript?

Is there any way to get a list of all the menu items under a menu heading like File or Edit with AppleScript?

I've found some related questions, but nothing exact. No luck on Google either.

I'm trying to get a list of which files are open in Photoshop's Window menu, and figure out which one has the check mark.

screenshot-with-shadow.png

I think I might be able to do the second part by using something like " In Applescript, how can I find out if a menu item is selected/focused? " and the Accessibility Inspector since it has AXMenuItemMarkChar

screenshot-with-shadow.png

like image 877
cwd Avatar asked Nov 12 '12 01:11

cwd


1 Answers

I don't have Photoshop but this works for Illustrator:

activate application "Adobe Illustrator"
tell application "System Events"
    tell process "Adobe Illustrator CS5.1"
        set xxx to name of every menu item of menu 1 of menu bar item "Window" of menu bar 1
    end tell
end tell

To get an attribute you can use:

activate application "Adobe Illustrator"
tell application "System Events"
    tell process "Adobe Illustrator CS5.1"
        set xxx to value of attribute "AXMenuItemMarkChar" of menu item "tools" of menu 1 of menu bar item "Window" of menu bar 1
    end tell
end tell

nil scenario:

activate application "Adobe Illustrator"
tell application "System Events"
    tell process "Adobe Illustrator CS5.1"
        set xxx to value of attribute "AXMenuItemMarkChar" of menu item "Brushes" of menu 1 of menu bar item "Window" of menu bar 1
        try
            xxx
        on error
            -- insert your code
            beep 2
        end try
    end tell
end tell
like image 106
adayzdone Avatar answered Nov 05 '22 00:11

adayzdone