title: Applescript: on clicking Menu Bar item via gui script
body: <p>I'm trying to make an applescript for an application called F.lux that clicks the menu item &quot;Disable for an Hour&quot; as indicated in the screenshot below:</p>
  <p><img src="https://i.stack.imgur.com/fz0QP.png" alt="enter image description here" /></p>
  <p>The element path is indicated in the screenshot below:</p>
  <p><img src="https://i.stack.imgur.com/QafW4.png" alt="enter image description here" /></p>
  <p>Here is my code thus far:</p>
  <pre class="lang-applescript prettyprint-override"><code>tell application &quot;System Events&quot;
      tell process &quot;Flux&quot;
          click (menu bar item 1 of menu bar 2)
          click menu item &quot;Disable for an hour&quot; of menu 1 of menu bar item 1 of        
          menu bar 2
      end tell    
  end tell
  </code></pre>
  <p>Everything compiles fine, however I keep getting the error message below when I attempt to run the script:</p>
  <blockquote>
  <p>error &quot;System Events got an error: Can’t get menu 1 of menu bar item 1 of menu bar 2 of process &quot;Flux&quot;. Invalid index.&quot; number -1719 from menu 1 of menu bar item 1 of menu bar 2 of process &quot;Flux&quot;</p>
  </blockquote>
  <p>Can someone pinpoint where I'm going wrong with this?</p>