Categories
Uncategorized

How to Switch to a Specific Browser Tab with AutoHotkey

Do you have a bunch of tabs open in your web browser and you want switch to the one with a specific title?

This script will loop through all of the open tabs in your browser and stop when it finds part of the page title that says “Automate This”.


NumOfTimesToCheck = 40 ; timeout - circle through tabs this many times
TimesChecked = 0
SetTitleMatchMode 2
needle := "Automate This"
WinActivate, Chrome
Loop {
  TimesChecked++
  if (NumOfTimesToCheck == TimesChecked)
    return
  WinGetTitle, title
  IfWinNotActive, Chrome
    break
  if (InStr(title,needle))
    Break
  Else
    send ^{Tab}
  sleep 50
}

It contains a timeout, NumOfTimesToCheck, which means if the script can’t find the tab it’s looking for after 40 tries it will stop. If you have more than 40 tabs open, you will want to increase this value.

Another thing to note is that this script will stop when it finds the first tab that contains the needle in the title. If there are two tabs with the words “Automate This” in the title, it will stop at the first one it encounters, which might not be the one you want. To prevent this, make sure each tab you’re trying to find has a unique title, and if two titles are similar, try to make the needle as detailed as possible.

This script works with Chrome. Want to use Firefox instead? Replace WinActivate, Chrome with WinActivate, Firefox

Leave a Reply

Your email address will not be published. Required fields are marked *