title: Using AppleScript to grab the URL from the frontmost window in web browsers: The definitive list
body: <p>I built a <strong>[widget][1]</strong> that grabs the URL from the frontmost window in Safari, then allows you to shorten it using the tr.im API. Works sweet as.</p>
  
  <p>I want to make this more flexible, so am investigating how to grab an URL from other browsers. Here's the AppleScript that works in Safari:</p>
  
  <pre><code>tell application "Safari"
      return URL of front document as string
  end tell
  </code></pre>
  
  <p>After <a href="https://web.archive.org/web/20141112082406/http://hintsforums.macworld.com/showthread.php?t=32237" rel="nofollow noreferrer">some digging</a>, I determined that the following <em>might</em> work for Firefox (though one person has told me it doesn't work for him, possibly a conflict with some extension?):</p>
  
  <pre><code>tell application "Firefox"
      set myFirefox to properties of front window as list
      return item 3 of myFirefox
  end tell
  </code></pre>
  
  <p><em>Note: The above is an example of a less-than-best practice, relying on the position of list items. See below for a better solution for Firefox.</em></p>
  
  <p>What I'd like to do is build a list here of the definitive equivalents for every modern browser on the Mac: Opera, Camino, Flock, etc.</p>
  
  <p><strong>Update:</strong> In my research on the subject, I came across a helpful thread on <a href="http://www.macosxhints.com/article.php?story=20060325015454467" rel="nofollow noreferrer">MacOSXHints.com</a>. Most of my answers below are based on that discussion.</p>
  
  <p><strong>Update 2:</strong> I've incorporated the AppleScript on this page into the [widget][1]. It seems to be working swell.</p>