luliger
luliger

Reputation: 33

Applescript clicking nested menu items

very simple question but I am trying to click a menu item that is in a list in a menu - i.e. clicking "Text Encoding" in the menu brings up a list of different kinds of encoding. I want to choose a certain kind of encoding using applescript. Here's my attempt:

tell application "System Events" to tell process "iChm"
    click menu item "Text Encoding" of menu "View" of menu bar item "View" of menu bar 1
    click menu item 2 of last menu item
end tell

Thanks very much!

Upvotes: 2

Views: 1707

Answers (2)

CRGreen
CRGreen

Reputation: 3444

I think it would be nice to know what you're trying to click exactly. If it is the "Unicode (UTF-8)" item, notice that there are (probably a type-o by the developer) TWO spaces after Unicode:

"Unicode  (UTF-8)"
        ^^

So if you do:

tell application "System Events"
    click menu item "Unicode  (UTF-8)" of menu "Text Encoding" of menu item "Text Encoding" of menu "View" of menu bar item "View" of menu bar 1 of application process "iChm"
end tell

... it will work.

Upvotes: 0

Lri
Lri

Reputation: 27603

tell application "System Events" to tell process "iChm"
    tell menu item "Text Encoding" of menu 1 of menu bar item "View" of menu bar 1
        click menu item 3 of menu 1
    end tell
end tell

For some menu items you need to click the menu bar item first:

tell application "System Events" to tell (process 1 where it is frontmost)
    tell menu bar item 3 of menu bar 1
        click
        click menu item "Open Recent" of menu 1
    end tell
end tell

Upvotes: 2

Related Questions