How to Distinguish Between Chrome Tabs with the Same Title?

I often have as many as half a dozen different Chrome windows open, each with as many as a dozen different tabs. Many of them have the same name, and in different windows.

I want to be able to somehow record which tab I have open when I activate a macro because the macro will change to a different window, maybe even in a different desktop/workspace, and then I want to be able to return to the "calling" window and tab, that is, the window and tab I was in when I called the macro.

Everything I've found online so far only seems to be able to tell tabs apart by their titles. When I have a couple of dozen tabs with the same title, those seem like they'd be useless to me. Even if I iterated across all the tabs, how do I tell which one was the calling window/tab when then content is always going to be different?

Any ideas how to simply return to where I started within all my Chrome windows and tabs after invoking a macro that takes me somewhere else?


Look at the Tab class in the Google Chrome AppleScript dictionary.

Use Script Debugger NOT Apple's Script

(SD's commercial version reverts to its freeware “Lite” version after a 30 day demo period, and still totally beats the pants off of the Script

tell application "Google Chrome"
   tabs of windows
end tell

Working with Tab IDs is not simple in Chrome, because they cannot be activated as an object (BAD Google!).

You have to crack the tab reference apart yourself to get its parent window.

tell application "Google Chrome"
   set tabRef to active tab of window 1
      tabRef / 0
   on error errMsg
      set AppleScript's text item delimiters to {"id ", " of"}
      set tabID to text item 2 of errMsg
      set winRef to window id (text item 4 of errMsg)
   end try
end tell

Tabs have ID numbers but they are referenced by index in their parent window.

So you have to loop through the tabs in the target window and look for the correct ID, while keeping track of the tab index.

Then there's the long standing evil macOS window index bug that makes activating a given window a challenge...

Have fun.



Thanks @ccstone,

So you're telling me that if I do a little hurdle jumping, I can get the Tab ID, but then I'm not going to be able to use it to re-activate my original window and tab?

Oh well ...


You can – it just takes work.

Take a look at this script:

Google Chrome – How to Bring an Existing GMail Tab to the Front - #16 by ccstone

Thanks Chris,

That looks like it just looks at every tab and tests the URL. Following that idea, to return to the tab I started from, I would save the starting URL, do my other things, and then find the tab with that URL again.

Does this AppleScript loop test things fairly quickly? If I had 70 or more tabs open would I have to sit and wait a minute to resume what I was doing? Or would it get there in a couple of seconds?


I already gave you the means to get back to your tab.

The gmail activation script demonstrates other techniques – including how to get your window/tab to the front.

As for speed – why would you not just try it out?

I wrote it 6+ years ago, and it was fast then.


Well, no, what you said was

So I haven't tried that route yet, and thought this new one might be easier.

As for trying, I'm both lazy and in a hurry. So I thought I'd ask first before embarking on a research project to test whether or not this approach was even viable. :wink:

Thanks. I appreciate the help.

Open Gmail – mix up your windows – run the macro.

Not much time or effort to test...