SCRIPT: Activate Google Chrome Tab for Specified URL

Continuing the discussion from Bring a specified window of an app to the front (if there are more than one window):

@kreal, I decided to make a new topic for this.

This is an interesting topic/script. Last year I raised this question in the Script Debugger forum, and we had a little contest that was very enlightening. See

Also See:
Make Safari Window with URL FrontMost

UPDATED: 2018-10-13 18:00 GMT-5
VER: 1.2
Fix activation of Chrome to make frontmost window active.

property ptyScriptName : "Activate Google Chrome Tab for Specified URL"
property ptyScriptVer : "1.2" --  ADD Activate Google command
property ptyScriptDate : "2018-10-13"
property ptyScriptAuthor : "estockly" -- adapted for KM by JMichaelTX

  • Activate Google Chrome Tab for Specified URL
      • If URL is for existing Tab, that Window/Tab will be made frontmost
      • Else a new Tab in frontmoat Window will be added for URL
RETURNS:  Chrome Window/TAB with Requested URL at Front

  1.  macOS 10.11.6+
  2.  Mac Applications
      • Google Chrome
TAGS:  @CAT.Web @CAT.Windows @SW.Chrome @type.Example @Lang.AS @Auth.Other @CAT.URL

REF:  The following were used in some way in the writing of this script.

  1.  2017-05-14, estockly, Late Night Software Ltd.
      What is Best Method to Activate Google Chrome Tab for Existing URL? (Ques by @JMichaelTX)
~~~ MY QUESTION on the SD FORUM ~~~
What is Best Method to Activate Google Chrome Tab for Existing URL?


Congratulations Ed! Your script is the fastest by 2X when run against my standard test from above 
(10 win with 20 total tabs):
    @JMichaelTX:  0.39     @ccstone: 0.38       @estocky: 0.17


tell application "Keyboard Maestro Engine" to set urlToFind to getvariable "URLToFind"

tell application "Google Chrome"
  set windowTabList to URL of tabs of every window
  set targetURL to urlToFind
  set found to false
  set windowIndex to 1
  repeat with thisWindowsTabs in windowTabList
    set TabIndex to 1
    repeat with TabURL in thisWindowsTabs
      if TabURL as text = targetURL then
        set index of window windowIndex to 1
        set active tab index of window 1 to TabIndex
        set found to true
        exit repeat
      end if
      set TabIndex to TabIndex + 1
    end repeat
    if found then exit repeat
    set windowIndex to windowIndex + 1
  end repeat
  if not found then
    make new tab at window 1 with properties {URL:targetURL}
  end if
end tell

--- Force macOS to Actually Make the Window FrontMost ---

tell application "System Events"
  tell application process "Google Chrome"
    tell (front window) to perform action "AXRaise"
  end tell
end tell

return "OK"


The script works very well!

1 Like

I'm embarrassed to ask you this: where do I paste the URL in question in your apple script?
thanks very much

1 Like

Nothing to be embarrassed about. It is my bad for not making it clear.
Normally I post a full macro with any script I post, but I deviated in this case.

Just set the KM Variable "URLToFind" to your target URL, and then run the script.
The key is the first line of code:
tell application "Keyboard Maestro Engine" to set urlToFind to getvariable "URLToFind"



thanks very much !

To make this work with just tab titles I had to change a small part of the script to this:

set windowTabList to title of tabs of every window

That way I was able to search by tab title. Ideally I would want to use a more flexible approach for partial match or just containing text...

this macro is a gem !

just a minor issue. I discovered that for the macro to work, you can't have Chrome active without any tab already open.

Can I simply just activate the 1st tab (irrespective of url)?

I am doing something with only 2 tabs anyway

Yes, easily:


1 Like

You don't need KM for that. ⌘1 thru ⌘9 will activate the nth Tab in that window.
Also, ⌃⇥ and ⌃⇧⇥ will move one tab forward and backward.

1 Like

Thanks a lot @gglick and @JMichaelTX

Can you provide the script with your newly added modification ? I'm not familiar with this.