Applescript to show Apple menu bar items
Asked Answered
F

4

3

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.

Fingerstall answered 5/5, 2013 at 23:42 Comment(0)
C
4

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.

Civvies answered 6/5, 2013 at 8:36 Comment(4)
....but, did not serve my purpose. The script changes the menu bar itself (to Finder's menu bar). Although I want to actually show the Apple menu items, I want to keep the original app's menu bar unchanged (-.-)Fingerstall
What are you running it with? It shows the menu bar for the current application when I run with FastScripts.Civvies
Sorry, I was wrong. It works great and perfectly serves my purpose. Many thanks again d(^_^) <- thumbs up!Fingerstall
@T_T, Please have a look at: What should I do when someone answers my question?Ommatophore
K
1

Do you want to actually show the menu items, i.e. either in the open menu or in a dialog window, or do you only want to select a menu item from a menu?

If you run the following script, the Apple menu will open. Use ASCII characters 28-31 to navigate the menus.

tell application "System Events"
  -- focus
  key code 120 using control down
  -- navigate
  keystroke (ASCII character 31)
end tell

Universal access must be turned on and menu navigation must be on too. If menu navigation is off, you need to type Control-F1 to turn it on. You can do this by script, but I don't know how to use AppleScript to check its status. The keycode for F1 is 122.

Kerch answered 6/5, 2013 at 8:2 Comment(3)
Thanks for your reply. But the script did not work in Applescript Editor (run). I got "error number -10004" for ASCII character 31. (I want to actually show the menu items.)Fingerstall
Apparently your setup is different from mine. It works perfectly here. But I see you already solved it.Kerch
Just for your info. I use Japanese OS X 10.8.3 with a Japanese keyboard on MacBookPro. Thanks anyway (^_^)/Fingerstall
I
0

This worked for me to click on a VPN application that runs in the menubar:

tell application "System Events" to tell process "GlobalProtect"
    click menu bar item 1 of menu bar 2
end tell

So in the OP case, replacing "GlobalProtect" with "Finder" and menu bar 2 with menu bar 1 would maybe make it work... it doesn't seem to do anything visually when I test it, but it may be doing stuff in the background... maybe further keypresses or something would do what you want?

Iseult answered 23/8, 2019 at 13:33 Comment(0)
P
-3

Try this one out. It uses a function instead of the complicated tell structure you are currently utilizing.

tell application "Finder" to activate
menu_click({"Finder", "View", "Arrange By", "Size"})
Pterous answered 5/5, 2013 at 23:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.