Re: Menulet scripting
Re: Menulet scripting
- Subject: Re: Menulet scripting
- From: Bill Cheeseman <email@hidden>
- Date: Tue, 27 Jun 2017 09:43:34 -0400
> On Jun 27, 2017, at 7:24 AM, Bob Stern <email@hidden> wrote:
>
> I cannot access any of the menu items by index number because AppleScript
> reports the menu extra as having only one menu bar item:
>
> tell application "System Events"
> tell menu bar 1 of process "exaSoundDashboard"
> count menu bar items -- returns count = 1.
> end tell
> end tell
I think you have misunderstood the UI element hierarchy of a third-party
application's menu extra. Assuming exaSoundDashboard is an application that
installs a menu extra, it must have its own special menu bar for the menu
extra, menu bar 2, which you appear to have overlooked. That special menu bar 2
contains a single menu bar item, menu bar item 1, which is the menu extra
itself. That menu extra, menu bar item 1, in turn contains a single menu, menu
1, which is the menu extra's menu, visible only after you click the menu extra
to open its menu. Finally, that menu contains the menu items or commands that
you can see and click after you open the menu extra's menu.
Part of the confusion goes with all menu bars. Users can only see the menu bar
(with its visible menu titles) and the opened menu (with its visible menu items
or commands). But in fact there is a hidden menu bar item between the menu bar
and the menu; namely, the hidden menu bar item represented by the menu bar's
menu title. This often confuses scripters the first time they try to use GUI
Scripting to control an application's menus and menu items.
It is even more confusing with regard to menu extras, for a couple of
additional reasons. First, the menu extra is the hidden menu bar item. The fact
that it is hidden is a surprise the first time you dive into this area. It may
also be confusing because, in the case of some applications, the application
menu bar, menu bar 1, contains only a single menu bar item, which is easily
mistaken for the menu extra. In fact, menu bar 1 is the application's menu bar.
In most applications, menu bar 1 contains several menu titles and their
associated menu bar items, such as the application name, and the "File", "Edit"
and other menu bar titles. But some specialized applications, which exist only
or primarily to install a menu extra, contain a single application menu bar
item in menu bar 1, usually named for the application. It looks like
exaSoundDashboard is one of those applications, since your scripts discovered
that its menu bar 1 contains only 1 menu bar item. But I'm sure it contains a
second menu bar, menu bar 2, which is the one you want to use to get at the
menu extra installed by the application.
For an example, here is an AppleScript snippet that displays (and returns as a
list) all of the menu items in the SoundSource third-party menu extra included
with SoundSource, an application from Rogue Amoeba
<http://www.rogueamoeba.com/freebies/>. I tested this successfully on El
Capitan:
tell application "System Events"
tell process "SoundSource"
tell menu bar 2 -- application's menu extras menu bar
tell menu bar item 1 -- application's menu extra
click -- open the menu
tell menu 1 -- menu extra's menu
get every menu item -- the menu extra's
commands
end tell
end tell
end tell
end tell
end tell
--
Bill Cheeseman - email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden