4

I have several tabs open in Firefox. I want AutoIt to activate a particular tab in Firefox. How can this be done?

user4157124
  • 2,809
  • 13
  • 27
  • 42
neuromancer
  • 53,769
  • 78
  • 166
  • 223

6 Answers6

5

Give the whole browser window focus, then use the send command to repeatedly send it cntl-tab until the window's title is the name of the tab you want (with - Mozilla Firefox at the end).

Jeanne Pindar
  • 617
  • 7
  • 15
  • 1
    I saw someone do it without having to alt-tab through all of the window titles using autoit, but I don't know how they did it because I didn't see the source. – neuromancer Jun 02 '10 at 02:00
5

There's a UDF (User Defined Functions -include file) called FF.au3. Looks like the function you want is _FFTabSetSelected(), good luck!

Below is an example of Jeanne Pindar's method. This is the way I would do it.

#include <array.au3>

Opt("WinTitleMatchMode", 2)

activateTab("Gmail")
Func activateTab($targetWindowKeyphrase)
    WinActivate("- Mozilla Firefox")
    For $i = 0 To 100
        If StringInStr(WinGetTitle(WinActive("")),$targetWindowKeyphrase) Then
            MsgBox(0,"Found It", "The tab with the key phrase " & $targetWindowKeyphrase & " is now active.")
            Return
        EndIf
        Send("^{TAB}")
        Sleep(200)
    Next
EndFunc
user4157124
  • 2,809
  • 13
  • 27
  • 42
Copas
  • 5,921
  • 5
  • 29
  • 43
  • 3
    The FF.au3 include requires that MozRepl be installed, you can get it here: https://github.com/bard/mozrepl/wiki. – MaQleod Sep 05 '11 at 22:20
4

Here you go...

AutoItSetOption("WinTitleMatchMode", 2)

$searchString = "amazon"

WinActivate("Mozilla Firefox")
For $i = 0 To 100
    Send("^" & $i)
    Sleep(250)
    If Not(StringInStr(WinGetTitle("[ACTIVE]"), $searchString) = 0) Then
        MsgBox(0, "Done", "Found it!")
        ExitLoop
    EndIf
Next

Just delete the MsgBox and you're all set!

sth
  • 222,467
  • 53
  • 283
  • 367
MemphiZ
  • 766
  • 2
  • 13
  • 29
2

As Copas said, use FF.au3. Function _FFTabSetSelected($regex,"label") will select first tab with name matching given $regex.

atomizer
  • 4,458
  • 1
  • 17
  • 9
  • +1 about 1 line code & +1 about do not send events. UNLIKE any `send` or `click` to active windows when you can use Objects. This is the correct way to set selected Tab. Doing that you can close a Tab without interfere other windows, also if the Windows containing the tab is Hidden. – m3nda Jun 04 '14 at 06:06
0

Nop... The script is buggy ^^'... no need to count to 100, and there is a problem with the "send" after it:

If you send ctrl + number =>the number can't be bigger than 9... Because ten is a number with 2 caracters, Firefox can't activate tab 10 with shortcut.

And by the way when the script is working there is a moment he release the ctrl key.. It don't send ten, but ctrl and 1 end zero ... and splash !!! It just send the number in the window. So we need to learn to the script that the second time he's back to $i = 0 or one, all the tabs was seen, no need to continue, even if the text you're searching for was not found. So I made my own script based on the old one:

##
AutoItSetOption("WinTitleMatchMode", 2)

$searchString = "The string you're looking for"
Local $o = 0
WinActivate("The Name of the process where you're searching")
For $i = 0 To 9
   Send("^" & $i)
   Sleep(250)
      if ($i = 9) Then
         $o += 1
      EndIf
      If not (StringInStr(WinGetTitle("[ACTIVE]"), $searchString) = 0) Then
            MsgBox("","","Found it !") ;your action,  the text was found.
            ExitLoop
      ElseIf ($o = 1) Then
            MsgBox("","","All tab seen, not found...") ;your action, the text was not found, even after looking all title.
            ExitLoop
      EndIf
   Next
##
Claod
  • 11
  • 1
  • 8
-4

I haven't touched AutoIt in years, but IIRC it will be:

setMousePos(x, y)    // tab position
click("left")
Amy B
  • 17,874
  • 12
  • 64
  • 83