Applescript: on clicking Menu Bar item via gui script

前端 未结 1 733
南笙
南笙 2020-12-01 03:14

I\'m trying to make an applescript for an application called F.lux that clicks the menu item \"Disable for an Hour\" as indicated in the screenshot below:

相关标签:
1条回答
  • 2020-12-01 04:00

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

    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
    

    One workaround 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
    
    0 讨论(0)
提交回复
热议问题