Search code examples
safariapplescriptaddress-bar

How to get the current address of Safari's address bar with AppleScript


I want to read the address out of the address bar of a safari window with AppleScript.

One can use keystroke-simulating with cmd+l, cmd+c and subsequently read out the clipboard. But this is obviously a very ugly hack.


Solution

  • Something like this should work to get the URL of the active tab in the last used window;

    tell application "Safari"
        set w to first window
        set t to current tab of w
        display dialog (URL of t as string)
    end tell