title: How to get the title of the current Aquamacs window using applescript
body: <p>I'm trying to programmatically retrieve the major mode of aquamacs. I had a few ideas: get the menubar items, get the window title and parse it using regexes. </p>
  
  <p>I've tried both, and ran into a problem, both the menubar and window arrays are empty, which makes it impossible to do this: </p>
  
  <pre><code>on test()
  try
      tell application "System Events"
          if application "Aquamacs" exists then
              -- display notification "It's aquamacs"
              tell application "Aquamacs" to activate
              if menu bar item "File" of menu bar 1 exists then
                  display notification "File exists"
                  --Fails when the file menu bar item clearly is there
              else
                  display notification "File doesn't exist"
              end if
          else
              display notification "It isn't aquamacs"
          end if
      end tell
  
  end try
  end test
  
  test()
  </code></pre>
  
  <p>or this: </p>
  
  <pre><code>on getAppTitle(appN)
  
  tell application appN
      activate
  end tell
  
  tell application "System Events"
      # Get the frontmost app's *process* object.
      set frontAppProcess to first application process whose frontmost is true
  end tell
  
  # Tell the *process* to count its windows and return its front window's name.
  tell frontAppProcess
      if (count of windows) &gt; 0 then --never runs because count is always zero
      set window_name to name of every window
  
      end if
  end tell
  end getAppTitle
  
  getAppTitle("Aquamacs")
  </code></pre>
  
  <p>and then looking at the file extension. </p>
  
  <p>I don't understand why there's such inconsistency between the system and AppleScript: it clearly has windows which definitely have titles, yet somehow are out of reach of scripts. </p>