title: Applescript to run Detect Displays
body: <p>When I plug an external monitor into my Macbook and wake it, the display is often the wrong resolution. Prior to Mountain Lion, I was able to run the following applescript to detect displays:</p>
  
  <pre><code>tell application "System Preferences" to activate
  tell application "System Events"
      tell process "System Preferences"
          click menu item "Displays" of menu "View" of menu bar 1
          tell button "Detect Displays" of window 1 to click
      end tell
  end tell
  tell application "System Preferences" to quit
  </code></pre>
  
  <p>But, with 10.8, the "Detect Displays" button requires that you press the <strong>Option</strong> key to display it, and so the script gives the following error:</p>
  
  <blockquote>
    <p>error "System Events got an error: Can’t get button \"Detect
    Displays\" of window 1 of process \"System Preferences\"." number
    -1728 from button "Detect Displays" of window 1 of process "System Preferences"</p>
  </blockquote>
  
  <p>My applescript skills are less than rudimentary and my google-fu has not enabled me to stumble across an answer.  </p>
  
  <p><em>How can I modify the script to click the now hidden detect displays button?</em></p>