title: AppleScript - How do I detect if a specific button is clicked on GUI and terminate the script?
body: <p>I have a script that manipulates a GUI. At some point in the process, a progress indicator appears in the GUI for a few mins. If the user clicks the GUI button <code>button &quot;Stop&quot; of sheet 1</code> (so not a dialog button), I'd like the script to <code>display dialog</code> followed by <code>error number -128</code>. How do I do this? Here's what I tried...</p>
  <pre><code>repeat while progress indicator 1 of sheet 1 exists
    try
      set button_returned to button returned of button &quot;Stop&quot; of sheet 1
      if button_returned is &quot;Stop&quot; then
        display dialog &quot;Operation cancelled&quot;
        error number -128
      end if
    end try
  end repeat
  </code></pre>
  <p>Note: I use <code>repeat while progress indicator 1 of sheet 1 exists</code> to pause the script whilst the progress indicator is up.</p>