5

I am trying to learn to access any menu item within an application with AppleScript. I can orient to the actual menu tab, and then access clickable menu items, but I can't access menu items within submenues that appear if they are hoovered over or RightArrow is pressed.

In the code below, "Zoom" is this type of menu item, and can't be found using the term 'menu item'. What term should I use instead so I can access "Zoom in"?

1 tell application "Firefox"
2   activate
3   tell application "System Events"
4       tell process "Firefox"
5           click menu item "Zoom in" of menu item "Zoom" of menu "Tools" of menu bar 1
6       end tell
7   end tell
8 end tell

Note: "Zoom in" has, by chance, a shortcut "CMD" and "+", but this is not a solution.

Additional question: How do I pick "the first", "the last" or the "n:th" menu item?

2 Answers 2

10

There are a couple of things.

First you will need a delay between the Activation of the App (Firefox) and the click action.

If you do not,the click action will be fire way too soon for the application to pick it up.

Secondly, in my FirfFox the Zoom in Menu item is under the View menu.

So the code needs to work back from the Zoom in menu item back to the initial Menu item taking in all the nodes in between.

click menu item "Zoom In" of menu 1 of menu item "Zoom" of menu 1 of menu bar item "View" of menu bar 1

activate application "Firefox"
delay 1
tell application "System Events"
    tell process "Firefox"
        click menu item "Zoom In" of menu 1 of menu item "Zoom" of menu 1 of menu bar item "View" of menu bar 1

    end tell
end tell

Each Sub menu item must have a controlling menu

So you could even use.

click menu item "Zoom In" of it's menu of menu item "Zoom" of it's menu of menu bar item "View" of menu bar 1
0

This one is a bit tricky since you have to select the menu for example :

tell application "Firefox"
    activate
    tell application "System Events"
        tell process "Firefox"
            click menu item 1 of menu 1 of menu item 1 of menu 1 of menu bar item "Tools" of menu bar 1

        end tell
    end tell
end tell

This piece of code will call the first item (the first in the submenu) of the first item of the Tools menu.

If you want to call the first or the last item just use the keyword last or first :

first menu bar item of menu bar 1
last menu bar item of menu bar 1

NB : You can replace the index of the item by its label.

1
  • Thanks! I was a bit confused by the long "of menu" line since it didn't have any actual menu item names, but when I broke it down I understood it. Thanks again! Jun 13, 2014 at 17:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .