Search code examples
applescriptmenubar

Applescript to show Apple menu bar items


I am an Applescript newbie. I want to know Applescript to show the Apple menu bar items from an arbitrary application (but the many bar should remain for the orginal application).

I tried the following script, using Finder as a kind of dummy app, but it did not work.

tell application "System Events"
    tell process "Finder"
        tell menu bar 1
            click menu bar item "Apple"
        end tell
    end tell
end tell

Can anyone help?

PS-1: I want to know this because Control-F2 to move focus to menu bar often does not work, as reported in the following link: https://apple.stackexchange.com/questions/12723/control-f2-move-focus-to-menu-bar-only-works-occasionally

PS-2: I tried to post an image, but not allowed.


Solution

  • process 1 where frontmost is true gets the frontmost process:

    tell application "System Events" to tell (process 1 where frontmost is true)
        click menu bar item 1 of menu bar 1
    end tell
    

    Clicking menu bar items doesn't work in full screen windows though. And if System Events is not used for a few minutes, it closes automatically, and there's a short delay when it's opened again.