Applescript: when you click the menu button via gui script

I'm trying to make applescript for an application called F.lux, which clicks on the โ€œDisable for an hourโ€ menu item, as shown in the screenshot below:

enter image description here

The path to the element is shown in the screenshot below:

enter image description here

Here is my code:

tell application "System Events" tell process "Flux" click (menu bar item 1 of menu bar 2) click menu item "Disable for an hour" of menu 1 of menu bar item 1 of menu bar 2 end tell end tell 

Everything compiles fine, however I keep getting the error message below when I try to run the script:

error "System events received an error: I can not get menu 1 of menu line 1 in menu line 2 of the" Flux "process. Invalid index." number -1719 from the menu 1 line menu item 1 line of the menu 2 of the process "Flow"

Can someone determine where I am wrong?

+6
source share
1 answer

This worked for me, but after the first click command, there is a delay of about 5 seconds.

 tell application "System Events" to tell process "Flux" tell menu bar item 1 of menu bar 2 click click menu item "Disable for an hour" of menu 1 end tell end tell 

A ignoring application responses is to use ignoring application responses and terminate system events after the click command:

 ignoring application responses tell application "System Events" to tell process "Flux" 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 "Flux" tell menu bar item 1 of menu bar 2 click menu item "Disable for an hour" of menu 1 end tell end tell 
+22
source

Source: https://habr.com/ru/post/944749/


All Articles