user8864088
user8864088

Reputation:

Applescript to click menu item of status bar app

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.

Upvotes: 7

Views: 4027

Answers (1)

pointum
pointum

Reputation: 3177

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

Upvotes: 2

Related Questions