Get the URL of the frontmost tab from Chrome on OS X?

前端 未结 5 2134
無奈伤痛
無奈伤痛 2021-02-07 14:12

Is there a way to do this to Chrome?

tell application \"Google Chrome\"
 return URL of front document as string
end tell

... doesn\'t work.

相关标签:
5条回答
  • 2021-02-07 14:34

    There is a simpler way to retrieve the URL.

    'tell application "Google Chrome" to return URL of active tab of front window'

    Tested and works like a charm.

    0 讨论(0)
  • 2021-02-07 14:37

    Now that Chrome (7+) supports AppleScript, you can do this:

    tell application "Google Chrome"
        get URL of active tab of first window
    end tell
    

    Note: "first window" refers to the frontmost window.

    0 讨论(0)
  • 2021-02-07 14:42

    No Applescript support: Issue 27468 - chromium - Applescript support for testing and scripting - Project Hosting on Google Code

    0 讨论(0)
  • 2021-02-07 14:44

    I think you can get the frontmost tab with this script:

    tell application "Google Chrome"
        set frontIndex to active tab index of front window
        get URL of tab frontIndex of front window
    end tell
    

    Hope I got this right. Try it out.

    0 讨论(0)
  • 2021-02-07 14:54

    Since there is no applescript support the only way it can be done is through GUI scripting, I'm not sure how familiar you are with applescript but gui scripting is a bad practice to get into. so take this code with caution. it is also important that you have access for assistive devices ENABLED in your Universal Access preferences.

      tell application "Google Chrome"
        activate
        tell application "System Events"
            tell application process "Google Chrome"
                get value of text field 1 of tool bar 1 of window 1
            end tell
        end tell
      end tell
    
    0 讨论(0)
提交回复
热议问题