Skip to content

Instantly share code, notes, and snippets.

@Chunjee
Last active October 20, 2022 19:29
Show Gist options
  • Save Chunjee/3ab74e1353391b6fe93d878b600872e5 to your computer and use it in GitHub Desktop.
Save Chunjee/3ab74e1353391b6fe93d878b600872e5 to your computer and use it in GitHub Desktop.
;/--\--/--\--/--\--/--\--/--\--/--\--/--\--/--\--/--\--/--\--/--\--/--\--/--\--/--\--/--\--/--\--/--\--/--\--/--\--/--\--/--\
; iterate through chrome tabs example
;\--/--\--/--\--/--\--/--\--/--\--/--\--/--\--/--\--/--\--/--\--/--\--/--\--/--\--/--\--/--\--/--\--/--\--/--\--/--\--/--\--/
;~~~~~~~~~~~~~~~~~~~~~
; Compile Options
;~~~~~~~~~~~~~~~~~~~~~
SetBatchLines -1 ;Go as fast as CPU will allow
#NoTrayIcon
#SingleInstance force
;~~~~~~~~~~~~~~~~~~~~~
; Variables
;~~~~~~~~~~~~~~~~~~~~~
SetTitleMatchMode, 2
; enter target tab title/partial title
vTitle := "Something Awful"
DetectHiddenWindows, Off
WinGet vList, List, % "ahk_exe chrome.exe"
; cycle through all chrome windows
Loop, % vList {
WinActivate, % "ahk_id" vList%A_Index%
WinWaitActive, % "ahk_id" vList%A_Index%
sleep, 25
hwnd := vList%A_Index%
; cycle through all tabs
Loop, 100 {
WinGetTitle, title_chromeTab, ahk_id %hwnd%
; quit this window if circled all the way back to first seen tab
if (title_chromeTab == firstTab) {
; msgbox, % "looped through " A_Index "Tabs."
break
}
; remember first tab so we know where to stop
if (A_Index == 1) {
firstTab := title_chromeTab
}
; if this is the windows we are looking for
if (InStr(title_chromeTab, vTitle)) {
msgbox, % "Found " title_chromeTab " for you!"
break 2
}
; proceed to next tab
Send ^{Tab}
sleep, 100
; msgbox, % title_chromeTab
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment