Help to find the active tab number in Firefox Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
carno
Posts: 176
Joined: 20 Jun 2014, 16:48

Help to find the active tab number in Firefox

14 Mar 2018, 17:02

I would like to get the tab number of the active tab I am reading in Firefox. By tab number I am referring to the order (sequence) number of the tab from the left. If it is the left-most (first) tab, then the number should be 1. if it is the second tab from the left the number should be 2, etc.
User avatar
jeeswg
Posts: 5956
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Help to find the active tab number in Firefox

14 Mar 2018, 17:48

- I have some half-answers.
- If the tab title is unique then these functions will work (in conjunction with WinGetTitle):
Firefox/Chrome, get tab names/focus tab - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 14#p139114
- If the tab title is not unique, then you can use code from the functions above, to get the screen coordinates of each tab button (using the Acc_Location function) and apply PixelGetColor to a tab, and the colour will tell you if the tab is focused or not.
- When I used AccViewer, I couldn't see any information that differentiated between the focused tab and the other tabs.
- There may be other methods that I don't know about.

Link:
Acc library (MSAA) and AccViewer download links - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26201
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
carno
Posts: 176
Joined: 20 Jun 2014, 16:48

Re: Help to find the active tab number in Firefox

14 Mar 2018, 17:59

Thanks! Are you specifically referring to this part of your code?:

Code: Select all

JEE_FirefoxFocusTabByName(hWnd, vTitle, vNum=1)
{
oAcc := Acc_Get("Object", "4", 0, "ahk_id " hWnd)
vRet := 0
for each, oChild in Acc_Children(oAcc)
	if (oChild.accName(0) == "Browser tabs")
	{
		oAcc := Acc_Children(oChild)[1], vRet := 1
		break
	}
if !vRet
{
	oAcc := oChild := ""
	return
}

vCount := 0, vRet := 0
for each, oChild in Acc_Children(oAcc)
{
	vTabText := oChild.accName(0)
	if (vTabText = vTitle)
		vCount++
	if (vCount = vNum)
	{
		oChild.accDoDefaultAction(0), vRet := A_Index
		break
	}
}
oAcc := oChild := ""
return vRet
}
User avatar
jeeswg
Posts: 5956
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Help to find the active tab number in Firefox  Topic is solved

14 Mar 2018, 18:03

Eureka! I think I've got it. I used some information that AccViewer doesn't show, but that arguably it *should* show.

Code: Select all

q:: ;Mozilla Firefox - get index of focused tab
WinGet, hWnd, ID, A
oAcc := Acc_Get("Object", "4", 0, "ahk_id " hWnd)
vRet := 0
for _, oChild in Acc_Children(oAcc)
	if (oChild.accName(0) == "Browser tabs")
	{
		oAcc := Acc_Children(oChild)[1], vRet := 1
		break
	}
if !vRet
{
	oAcc := oChild := ""
	return
}

vRet := 0
for _, oChild in Acc_Children(oAcc)
{
	;STATE_SYSTEM_SELECTED := 0x2
	if (oChild.accState(0) & 0x2)
		vRet := A_Index
}
oAcc := oChild := ""
MsgBox, % vRet
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 5956
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Help to find the active tab number in Firefox

14 Mar 2018, 18:24

- I was referring to any of the Firefox functions, they all do roughly the same thing.
- Anyhow, that code needed some tidying up, to add a bit more indentation, and to remove the word 'each', and use := instead of = for default values, I've just fixed it in the original link.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
carno
Posts: 176
Joined: 20 Jun 2014, 16:48

Re: Help to find the active tab number in Firefox

14 Mar 2018, 19:32

Thanks VERY much!! It works beautifully and that's all I wanted. Just the tab order number and it works like magic.

Return to “Ask For Help”

Who is online

Users browsing this forum: asad41163, swagfag, Tigerlily and 31 guests