I'v forgotten how to find a tab by its name and return the value (e.g tab 2) and eventually set the tab as the active tab too.
I've tried the following, but it's not working:
set titleString to "
"
tell application "Google Chrome"
set window_list to every window # get the windows
repeat with the_window in window_list # for every window
set tab_list to every tab in the_window # get the tabs
repeat with the_tab in tab_list # for every tab
set the_title to the title of the_tab # grab the title
if the_tab contains (Name to search" as text) then
display notification "the_tab"
end if
return # concatenate
end repeat
end repeat
end tell
I also tried to start something with JavaScript:
tell application "Google Chrome"
set window_list to every window
repeat with the_window in window_list
set tab_list to every tab in the_window
tell tab_list to set TheTab to execute javascript "document.title"
end repeat
end tell
But then I get:
{«class CrTb» id 4 of window id 1 of application "Google Chrome",
«class CrTb» id 9 of window id 1 of application "Google Chrome",
«class CrTb» id 2 of window id 1 of application "Google Chrome",
«class CrTb» id 189 of window id 1 of application "Google Chrome"}
doesn’t understand the “execute” message.
How can I proceed?
Best Answer
Not being sure of the total scope of what you're trying to accomplish, the follow code may be more then you needed. However, it does allow for searching the Tab's Name and then sets the Tab containing the search string as the
active tab
.The code below is a rework of the code presented in Find Safari Tabs with AppleScript. It would have been nice to have been able to change
tell application "Safari"
totell application "Google Chrome"
and the script worked, but because of the differences in the properties of a Tab between the two Apps, this is why that wouldn't work.What this script does:
active tab index
, meaning that Tab is now the current tab. If there's more then one window, the window containing that Tab is brought to the front of all other Google Chrome windows.active tab index
, meaning that Tab is now the current tab. If there's more then one window, the window containing that Tab is brought to the front of all other Google Chrome windows.