6

I have an app called Fenêtre, when looking process name using top command it gives the name Fene?~Btre H.

I would like to click the item called 'a.py' under its menubar item as shown in figure.

enter image description here enter image description here

My attempt:

attempt 1

tell application "System Events" to tell process "Fenêtre"
    tell menu bar item 1 of menu bar 1
        click
        click menu item "Show all" of menu 1
    end tell
end tell

Error:

$ osascript a.applescript 
a.applescript:121:157: execution error: System Events got an error: Can’t get menu item "Show all" of menu 1 of menu bar item 1 of menu bar 1 of process "Fenêtre". (-1728)

Note that, when I run only first and last line of attemp1 it runs good, when I add middle lines it fails to run.

attempt 2

ignoring application responses
    tell application "System Events" to tell process "Fenêtre"
        click menu bar item 1 of menu bar 2
    end tell
end ignoring
do shell script "killall System\\ Events"
delay 0.1
tell application "System Events" to tell process "Fenêtre"
    tell menu bar item 1 of menu bar 2
        click menu item "a.py" of menu 1
        -- click menu item 1 of menu 1 -- another try
    end tell
end tell

Updates (Still get errors)

tell application "System Events" to tell process "Fenêtre"
    get entire contents of menu bar 2
end tell

This gives:

{menu bar item 1 of menu bar 2 of application process "Fenêtre" of application "System Events"}

References:
Applescript: on clicking Menu Bar item via gui script
applescript click menu bar option
https://superuser.com/questions/587815/can-applescript-osascript-be-used-to-click-menu-extra-menu-items
Applescript to show Apple menu bar items
Is AppleScript UI Scripting very slow in general, or is it my script, or something else?
Clicking an applications menu bar item with AppleScript

Thanks a lot.

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
  • From your screenshot, Fenêtre appears to be a menu bar app. In my experiments with a different menu bar app here, it appears that the actually-visible menu bar item is in `menu bar 2`, not `menu bar 1`. However, for the app I was testing, there were no contents of that menu bar item visible to the Accessibility system (which is what System Events uses to access the UI). I don't know if that's particular to the app I was testing or general for all menu bar apps. What do you get from `get entire contents of menu bar 2`? – Ken Thomases Oct 20 '18 at 14:41
  • `tell application "System Events" to tell process "Fenêtre" get entire contents of menu bar 2 end tell` gives `{menu bar item 1 of menu bar 2 of application process "Fenêtre" of application "System Events"}` –  Oct 20 '18 at 15:42
  • `tell application "System Events" tell (first application process whose bundle identifier is "com.yoannmoinet.fenetre") get entire contents of menu bar 2 end tell end tell` gives the same thing `{menu bar item 1 of menu bar 2 of application process "Fenêtre" of application "System Events"}` –  Oct 20 '18 at 15:44
  • Yeah, that's roughly what I got with the app I tested. So that means the menu items aren't accessible this way. It may be that when the menu is actually open, the items are accessible, but I haven't tested. I know that issuing the `click` command on the menu bar item does cause it to open, but the command doesn't complete until the menu is dismissed, so you can't issue subsequent commands to find out. It may work to use `try` and `with timeout` to get control back while the menu is still up. – Ken Thomases Oct 20 '18 at 21:35
  • If none of these hints, suggestions and remarks do you any good –there simply ARE un-scriptable apps– you might have a look at an absolutely simple Foundation app/script (down under) that you can use (via osascript) to click ANY x/y screen coordinates no matter which app is responsible for this menu (item), button or window: https://apple.stackexchange.com/questions/316369/is-there-a-terminal-command-to-open-a-mac-menu-bar-item/342158#342158 – clemsam lang Nov 09 '18 at 18:13

1 Answers1

2

Use a bundle identifier instead of the app name:

tell application "System Events"
    tell (first application process whose bundle identifier is "BUNDLE_IDENTIFIER_HERE")
        tell menu bar item 1 of menu bar 1
            click
            click menu item "Show all" of menu 1
        end tell
    end tell
end tell
pointum
  • 2,987
  • 24
  • 31
  • 1
    Also try using something like `menu item 2` instead of using name or `return entire contents of menu 1` to figure out what’s inside. – pointum Oct 20 '18 at 12:14
  • 1
    how to find bundle identifier name? `"BUNDLE_IDENTIFIER_HERE". Invalid index.` –  Oct 20 '18 at 13:16
  • 1
    I tried `... bundle identifier is "com.yoannmoinet.fenetre"`, still gives `System Events got an error: Can’t get menu item "Show all" of menu 1 of menu bar item 1 of menu bar 1 of application process 1 whose bundle identifier = "com.yoannmoinet.fenetre".` –  Oct 20 '18 at 13:22
  • 2
    To find bundle list I used `/usr/libexec/PlistBuddy -c 'Print CFBundleIdentifier' /Applications/Fenêtre.app/Contents/Info.plist` –  Oct 20 '18 at 13:25
  • This answer is correct and works! All you have to do is change option name and find the bundle identifier on the Info.plist on /Applications/ folder. – mourodrigo May 17 '19 at 18:53
  • What about applications that aren't in /Applications like smaller apps that just appear on the Menu Bar? – volvox Jan 04 '23 at 18:17