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?
(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 Editor.app).
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
try
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...
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?
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?
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.