Cycle through chrome tabs until a specific one is found

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Elermino
Posts: 114
Joined: 29 Nov 2021, 17:43

Cycle through chrome tabs until a specific one is found

Post by Elermino » 20 Apr 2023, 10:11

Good day!
This script should go to Chrome and cycle through the tabs until it finds a specified one (in this case YouTube), then send a command and return to my initial window.
The problem is that it just switches to chrome and doesn't cycle through the tabs, even sometimes it bugs.
Thank you :)

Code: Select all

settitlematchmode, 2
^f1::
If Not WinExist("ahk_exe chrome.exe")
 {
 Return
 }
WinGetTitle, Title, A
WinActivate, ahk_class Chrome_WidgetWin_1
 Loop{

  WinGetTitle, CurrentWindowTitle, ahk_class Chrome_WidgetWin_1
  If CurrentWindowTitle contains YouTube
   {
   send {Space}
   ;~ Send {Alt down}   ;back to old window
   ;~ Send {tab}
   WinActivate, %Title%
   Sleep 300
   If not WinActive, ahk_exe chrome.exe
    {
    Send {Alt up}
    break
    Return
    }
   break
   Return
   } else {
   Send, ^{Tab}
   Sleep, 50
  }
 }
Return

Return to “Ask for Help (v1)”