Search code examples
macosapplescript

Getting Focused Browser Tabs in OSX


I am trying to get active browser tab from browsers. I can do that for Chrome with this code:

tell application "Google Chrome"
    set myURL to the URL of the active tab of the front window
end tell

For Safari, I am changing Chrome to Safari but it is not working at all

Is there anyone to help me about that?


Solution

  • For Safari it's:

    tell application "Safari"
        set myURL to the URL of the current tab of the front window
    end tell
    

    You also do not need to be so verbose, dropping all occurrences of the, e.g.:

    set myURL to URL of current tab of front window
    

    Does the same thing.

    In Script Editor, look in the Library for Safari:

    • Script Editor > Window > Library > Safari

    enter image description here