• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Accesing menu bar items.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accesing menu bar items.


  • Subject: Re: Accesing menu bar items.
  • From: kai <email@hidden>
  • Date: Wed, 21 Feb 2007 02:46:29 +0000


On 20 Feb 2007, at 03:39, Diego Barros wrote:

I was wondering if it was possible to select OS X menu bar items? Just to be clear, I am referring to the icons on the top-right in OS X. For example, the Bluetooth icon, volume control icon, etc.

I have an application that has a few menu items which I would like to select via AppleScript.

The first trick is to identify the required menu extra by its description, Diego - so that, whatever its current position in the menu bar, it should still be possible to target accurately.


We can get a list of descriptions with something like:

----------------

tell application "System Events" to value of ¬
	attribute "AXDescription" of menu bar items of ¬
	process "SystemUIServer"'s menu bar 1

--> {"AppleScript menu extra", "modem menu extra", "displays menu extra", "volume menu extra", "text input menu extra", "clock menu extra"} -- etc.

----------------

Assuming the menu items in question are named, they should be easier to identify by simply reading them from the menu.

The following handler takes a list containing the menu extra's description and the name of the required menu item(s):

----------------

to click_menu_extra at menu_list
tell application "System Events" to tell process "SystemUIServer"'s menu bar 1
click (first menu bar item whose value of attributes contains menu_list's beginning)
repeat with item_name in rest of menu_list
click (first menu item of result's menu 1 whose name is item_name)
end repeat
end tell
end click_menu_extra


click_menu_extra at {"displays menu extra", "1024 x 768, Millions"} -- modify as required

----------------

The subroutine should also handle varying levels of nested menu items, such as those indicated by the calling statements below. (The examples assume that library scripts are shown in the Script Menu.)

----------------

click_menu_extra at {"AppleScript menu extra", "Finder Scripts", "About Finder Scripts..."}

----------------

click_menu_extra at {"AppleScript menu extra", "URLs", "AppleScript Related Sites", "AppleScript Website"}

----------------

---
kai


_______________________________________________ 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/mailman//archives/applescript-users

This email sent to email@hidden
  • Follow-Ups:
    • Re: Accesing menu bar items.
      • From: Irwin Poche <email@hidden>
References: 
 >Accesing menu bar items. (From: "Diego Barros" <email@hidden>)

  • Prev by Date: Re: so what's going on here?
  • Next by Date: Mark Pinson is out of the office.
  • Previous by thread: Re: Accesing menu bar items.
  • Next by thread: Re: Accesing menu bar items.
  • Index(es):
    • Date
    • Thread