1

I want to create an AppleScript to click a menu but I can't what ever the script I using, here is the menu I want :

ELEMENT :
 Role : menu item
 Title: "sign in As..."
 Description :
 Help:
 Application: SytemUIServer

ELEMENT PATCH (starting at leaf element):
 menu Item "Sign in As..." (menu item 12)
  menu (menu 1)
   menu extra (menu bar item 2)
    menu bar (menu bar 1)
      application "SystemUIServer"

So I did a few script, the last one was

ignoring application responses
    tell application "System Events" to tell process "SystemUIServer"
        click menu bar item 2 of menu bar 1
    end tell
end ignoring
do shell script "killall System\\ Events"
delay 0.1
tell application "System Events" to tell process "SystemUIServer"
    tell menu item 12 of menu 1 of menu bar item 2 of menu bar 1
        click
    end tell
end tell

Also I just realise that the position can change (some time the item I want to click is menu item 12 sometime its 10 etc.)

Community
  • 1
  • 1
Kevin
  • 1,076
  • 4
  • 22
  • 49
  • ELEMENT : Role : menu item Title: "sign in As..." Description : Help: Application: SytemUIServer ELEMENT PATCH (starting at leaf element): menu Item "Sign in As..." (menu item 12) menu (menu 1) menu extra (menu bar item 2) menu bar (menu bar 1) application "SystemUIServer" – Kevin Apr 17 '15 at 12:46

1 Answers1

5

In your question, you didn't specify name of the menu bar item and name of the app which owns the menu bar item. That's the problem.

First, SystemUIServer only run menu bar items/icons native to OS X. To see the icons it runs, do these three lines separately in Script Editor.

1)

tell application "System Events" to tell process "SystemUIServer" ¬
to number of menu bars

2)

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

3)

tell application "System Events" to tell process "SystemUIServer" ¬
to title of menu bar items of menu bar 2

The results should look something like:

1) 2

2) {"Wi-Fi, four of four bars, with WiFiName.", "Battery: Charged ", "Clock"}

3) {"Notification Center", missing value}

Third-party apps, plus Spotlight, manage its own menu bar items/icons. Spotlight for example:

tell application "System Events" to tell process "Spotlight" ¬
to title of menu bar items of menu bar 1

This gives you: {"Spotlight"}

If you have Caffeine:

tell application "System Events" to tell process "Caffeine" ¬
to title of menu bar items of menu bar 1

You get: {missing value}, 'cause its programer didn't bother naming the item.

So if this is third-party menu bar item you are trying to script, it's not in SystemUIServer. If you only refer to the menu bar item with position instead of its name, you cannot reliably click it every time.

McUsr inserted this line, in order to save the edit that had to be of minimum 6 characters.

McUsr
  • 1,400
  • 13
  • 10
fartheraway
  • 363
  • 2
  • 8
  • 1
    Hi, thank you for your answer, the name of the menu bar its "apple connect" and its integrated in "SystemUIServer" – Kevin Apr 18 '15 at 21:54