4
votes

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.

1
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
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"}user8864088
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"}user8864088
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
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: apple.stackexchange.com/questions/316369/…clemsam lang

1 Answers

1
votes

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