Skip to content

Instantly share code, notes, and snippets.

@aztack
Created June 16, 2023 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aztack/3d20a7fcf6d221215b5731f5e541177c to your computer and use it in GitHub Desktop.
Save aztack/3d20a7fcf6d221215b5731f5e541177c to your computer and use it in GitHub Desktop.
ShowTabWitePrefix
on ShowTabWitePrefix(targetDomain) tell application "Google Chrome" set windowList to every window repeat with aWindow in windowList set tabList to every tab of aWindow set tabCount to count of tabList set currentTabIndex to 0 set targetTabs to {} -- Collect all the tabs matching the targetDomain prefix repeat with i from 1 to tabCount set aTab to item i of tabList considering case set tabURL to URL of aTab if tabURL starts with targetDomain then set end of targetTabs to {index:i, tab:aTab} end if end considering end repeat -- If there are any matching tabs, activate the next one in the list if (count of targetTabs) > 0 then set currentIndex to 0 repeat with i from 1 to count of targetTabs if active tab index of aWindow is (index of item i of targetTabs) then set currentIndex to i exit repeat end if end repeat -- if the current tab is the last matching one, activate the first one, else activate the next one if currentIndex is equal to (count of targetTabs) then set (active tab index of aWindow) to (index of item 1 of targetTabs) else set (active tab index of aWindow) to (index of item (currentIndex + 1) of targetTabs) end if set index of aWindow to 1 -- Bring window to front return end if end repeat end tell end ShowTabWitePrefix ShowTabWitePrefix("https://chat.openai.com")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment