Page 2 of 3

Re: Firefox/Chrome, get tab names/focus tab

Posted: 03 Oct 2018, 15:45
by jeeswg
@Pikoloco: The new functions might work, otherwise the old functions might work, otherwise you could try to modify them.

Re: Firefox/Chrome, get tab names/focus tab

Posted: 04 Oct 2018, 01:16
by Johnny R
Hallo jeeswg!
how to change "x.x.x.x.x"? "4.1.2.2.1" (for Chrome) doesn't work for Firefox v54.0.1, too. Your script https://autohotkey.com/boards/viewtopic.php?f=6&t=40615 works for notepad.
Thank You!

Re: Firefox/Chrome, get tab names/focus tab

Posted: 10 Oct 2018, 05:35
by jeeswg
I've added 2 functions to get the index of the focused tab, here:
Firefox/Chrome, get tab names/focus tab - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 12#p241912

JEE_FirefoxGetFocusedTabNum(hWnd)
JEE_ChromeGetFocusedTabNum(hWnd)

Re: Firefox/Chrome, get tab names/focus tab

Posted: 16 Dec 2018, 00:58
by nallan
Hi
I'm having an issue getting the JEE_ChromeFocusTabByName function working in google chrome 71. As far as I can tell it looks like the
oChild.accDoDefaultAction(0)
line isn't working. Has anyone else had this issue. I wonder if chrome broke the dodefaultaction on the tab to click it?

Re: Firefox/Chrome, get tab names/focus tab

Posted: 19 Dec 2018, 20:15
by jeeswg
- @nallan: Hello, do you manually or automatically update? My Chrome just updated to v71, and I had the same problem as you.
- I fixed the functions by replacing 4.1.2.2.1 with 4.1.2.1.1. I used this script to give me the numbers:
Acc: get text from all window/control elements - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=40615

- Here are functions to get the url for the active tab from Firefox/Chrome. Note: I can only get the url for the active tab, the urls for other tabs are not made available via Acc. (Note: the Firefox function is old, I haven't looked at it in a long time.)

Code: Select all

JEE_FirefoxGetUrl(hWnd, vOpt:="")
{
	local
	Loop, 10
	{
		vIndex := A_Index
		vAccPath := "application.tool_bar3.combo_box1.editable_text"
		;vAccPath := "4.25.3.2"
		if InStr(vOpt, "p") ;(pop-up window)
			vAccPath := "application.tool_bar1.combo_box1.editable_text"
		oAcc := Acc_Get("Object", vAccPath, 0, "ahk_id " hWnd)
		if !ErrorLevel
			break
		Sleep, 100
	}
	if (vIndex = 10)
		return

	vUrl := ""
	try vUrl := oAcc.accValue(0)
	oAcc := ""
	if !(vUrl = "") && !InStr(vUrl, "://")
		vUrl := "http://" vUrl
	return vUrl
}

Code: Select all

;acc path: 4.1.2.2.2.5.2
;acc path: 4.1.2.1.2.5.2
JEE_ChromeGetUrl(hWnd, vOpt:="")
{
	local
	oAcc := Acc_Get("Object", "4.1.2.2.2.5.2", 0, "ahk_id " hWnd)
	if !IsObject(oAcc)
	|| !(oAcc.accName(0) = "Address and search bar")
		oAcc := Acc_Get("Object", "4.1.2.1.2.5.2", 0, "ahk_id " hWnd)
	vUrl := oAcc.accValue(0)
	oAcc := ""
	return vUrl
}

Re: Firefox/Chrome, get tab names/focus tab

Posted: 04 Jan 2019, 17:50
by AHKStudent
Every update of Chrome (68 69 70 71) The numbers change.

Is there a way to know what the new numbers are without manually updating scripts?

Re: Firefox/Chrome, get tab names/focus tab

Posted: 01 Aug 2019, 13:36
by 20170201225639
The current path to use for getting tab counts in chrome (version 75) is: "4.1.2.1.1.1":

updated version:


Code: Select all

; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=26947
JEE_ChromeGetTabCount(hWnd){
	oAcc := Acc_Get("Object", "4.1.2.1.1.1", 0, "ahk_id " hWnd)
	for _, oChild in Acc_Children(oAcc)
	{
		vTabText := oChild.accName(0)
		if !(vTabText == "")
		&& !(vTabText == "New Tab")
			vCount++
	}
	oAcc := oChild := ""
	return vCount
}

Re: Firefox/Chrome, get tab names/focus tab

Posted: 27 Sep 2019, 13:40
by potroveio
how to invoke this function to show open tabs in Chrome on a tooltip when a hotkey is pressed?

thanks!

Martin

Re: Firefox/Chrome, get tab names/focus tab

Posted: 29 Sep 2019, 12:01
by potroveio

Code: Select all

;==================================================

JEE_ChromeGetFocusedTabNum(hWnd)
{
	oAcc := Acc_Get("Object", "4.1.2.2.1", 0, "ahk_id " hWnd)
	vRet := 0
	for _, oChild in Acc_Children(oAcc)
	{
		;STATE_SYSTEM_SELECTED := 0x2
		if (oChild.accState(0) & 0x2)
		{
			vRet := A_Index
			break
		}
	}
	oAcc := oChild := ""
	return vRet
}

Many thanks for these helfpul function - somehow I get tab number "0" for any tab on Chrome 77... any hints on how can I fix it? thanks!

Re: Firefox/Chrome, get tab names/focus tab

Posted: 29 Sep 2019, 18:35
by jeeswg
- Hello potroveio! I've updated the Chrome functions to work with v77.
- I've also added a few functions.
- [EDIT: 2019-10-01] And added Firefox equivalents that work with v69.
- Note: JEE_ChromeAccInit is where I now store the Acc paths, so if the Acc paths change again in future, you'll only have to change the paths inside that one function.
- Note: to use the functions with AHK versions pre-v1.1.27, remove the 'local' keyword in each function.

Code: Select all

;==================================================

;Firefox functions suite (tested on Firefox v69):

;requires Acc.ahk:
;Acc library (MSAA) and AccViewer download links - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=26201

;JEE_FirefoxAccInit(vValue)
;JEE_FirefoxGetUrl(hWnd:="", vOpt:="")
;JEE_FirefoxGetTabCount(hWnd:="")
;JEE_FirefoxGetTabNames(hWnd:="", vSep:="`n")
;JEE_FirefoxFocusTabByNum(hWnd:="", vNum:="")
;JEE_FirefoxFocusTabByName(hWnd:="", vTitle:="", vNum:="")
;JEE_FirefoxGetFocusedTabNum(hWnd:="")
;JEE_FirefoxAddressBarIsFoc(hWnd:="")
;JEE_FirefoxCloseOtherTabs(hWnd:="", vOpt:="", vNum:="")

;warning: JEE_FirefoxCloseOtherTabs:
;there is no separate Close button Acc element to do accDoDefaultAction on,
;so at present, each tab is focused, and Ctrl+W is sent to it, which is unreliable

;note: you can only get the url for the *active* tab via Acc,
;to get the urls for other tabs, you could use a browser extension, see:
;Firefox/Chrome: copy titles/urls to the clipboard - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=22&t=66246

;==================================================

;note: this function is redundant
;note: an equivalent function is needed for Chrome
JEE_FirefoxAccInit(vValue)
{
	local
}

;==================================================

JEE_FirefoxGetUrl(hWnd:="", vOpt:="")
{
	local
	if (hWnd = "")
		hWnd := WinExist("A")
	Loop 10
	{
		vIndex := A_Index
		vAccPath := "application.tool_bar3.combo_box1.editable_text"
		;vAccPath := "4.25.3.2"
		if InStr(vOpt, "p") ;(pop-up window)
			vAccPath := "application.tool_bar1.combo_box1.editable_text"
		oAcc := Acc_Get("Object", vAccPath, 0, "ahk_id " hWnd)
		if !ErrorLevel
			break
		;Sleep(100)
		DllCall("kernel32\Sleep", "UInt",100)
	}
	if (vIndex = 10)
		return

	vUrl := ""
	try vUrl := oAcc.accValue(0)
	oAcc := ""

	if InStr(vOpt, "x")
	{
		if !(vUrl = "") && !InStr(vUrl, "://")
			vUrl := "http://" vUrl
	}
	return vUrl
}

;==================================================

JEE_FirefoxGetTabCount(hWnd:="")
{
	local
	if (hWnd = "")
		hWnd := WinExist("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
	}

	vCount := 0
	for _, oChild in Acc_Children(oAcc)
	{
		;ROLE_SYSTEM_PUSHBUTTON := 0x2B
		if (oChild.accRole(0) = 0x2B)
			continue
		vCount++
	}
	oAcc := oChild := ""
	return vCount
}

;==================================================

JEE_FirefoxGetTabNames(hWnd:="", vSep:="`n")
{
	local
	if (hWnd = "")
		hWnd := WinExist("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
	}

	vHasSep := !(vSep = "")
	if vHasSep
		vOutput := ""
	else
		oOutput := []
	for _, oChild in Acc_Children(oAcc)
	{
		;ROLE_SYSTEM_PUSHBUTTON := 0x2B
		if (oChild.accRole(0) = 0x2B)
			continue
		try vTabText := oChild.accName(0)
		catch
			vTabText := ""
		if vHasSep
			vOutput .= vTabText vSep
		else
			oOutput.Push(vTabText)
	}
	oAcc := oChild := ""
	return vHasSep ? SubStr(vOutput, 1, -StrLen(vSep)) : oOutput
}

;==================================================

JEE_FirefoxFocusTabByNum(hWnd:="", vNum:="")
{
	local
	if (hWnd = "")
		hWnd := WinExist("A")
	if !vNum
		return
	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 || !Acc_Children(oAcc)[vNum]
		vNum := ""
	else
		Acc_Children(oAcc)[vNum].accDoDefaultAction(0)
	oAcc := oChild := ""
	return vNum
}

;==================================================

JEE_FirefoxFocusTabByName(hWnd:="", vTitle:="", vNum:="")
{
	local
	if (hWnd = "")
		hWnd := WinExist("A")
	if (vNum = "")
		vNum := 1
	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
	}

	vCount := 0, vRet := 0
	for _, 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
}

;==================================================

JEE_FirefoxGetFocusedTabNum(hWnd:="")
{
	local
	if (hWnd = "")
		hWnd := WinExist("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
			break
		}
	}
	oAcc := oChild := ""
	return vRet
}

;==================================================

JEE_FirefoxAddressBarIsFoc(hWnd:="")
{
	local
	if (hWnd = "")
		hWnd := WinExist("A")
	oAcc := Acc_Get("Object", "4", 0, "ahk_id " hWnd)
	vRet := 0
	for _, oChild in Acc_Children(oAcc)
	{
		if (oChild.accName(0) == "Navigation Toolbar")
			oAcc := oChild, vRet := 1
	}
	if !vRet
	{
		oAcc := oChild := ""
		return
	}

	oAcc := Acc_Children(oAcc).6
	oAcc := Acc_Children(oAcc).2
	;STATE_SYSTEM_FOCUSED := 0x4
	vIsFoc := !!(oAcc.accState(0) & 0x4)
	oAcc := oChild := ""
	return vIsFoc
}

;==================================================

;vOpt: L (close tabs to the left)
;vOpt: R (close tabs to the right)
;vOpt: LR (close other tabs)
;vOpt: (blank) (close other tabs)
;vNum: specify a tab other than the focused tab
JEE_FirefoxCloseOtherTabs(hWnd:="", vOpt:="", vNum:="")
{
	local
	if (hWnd = "")
		hWnd := WinExist("A")
	;vWinClass := WinGetClass("ahk_id " hWnd)
	WinGetClass, vWinClass, % "ahk_id " hWnd
	if !(vWinClass = "MozillaWindowClass")
		return
	if (vNum = "")
		vNum := JEE_FirefoxGetFocusedTabNum(hWnd)
	if (vOpt = "")
		vOpt := "LR"
	vDoCloseLeft := !!InStr(vOpt, "L")
	vDoCloseRight := !!InStr(vOpt, "R")

	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
	oChildren := Acc_Children(oAcc)
	vIndex := oChildren.Length() + 1
	Loop % vIndex - 1
	{
		vIndex--
		oChild := oChildren[vIndex]
		;ROLE_SYSTEM_PUSHBUTTON := 0x2B
		try
		{
			if (oChild.accRole(0) = 0x2B)
				continue
		}
		if (vIndex = vNum)
			continue
		if (vIndex > vNum) && !vDoCloseRight
			continue
		if (vIndex < vNum) && !vDoCloseLeft
			continue
		;note: cf. Chrome, Firefox doesn't have a separate Close button element
		;oChild2 := Acc_Children(oChild).4
		;if (oChild2.accName(0) = "Close")
		;	oChild2.accDoDefaultAction(0)
		;oChild2 := ""
		;instead we focus each tab and send Ctrl+W to it
		JEE_FirefoxFocusTabByNum(hWnd, vIndex)
		;Sleep(500)
		DllCall("kernel32\Sleep", "UInt",500)
		;ControlSend("{Ctrl down}w{Ctrl up}",, "ahk_id " hWnd)
		ControlSend, ahk_parent, {Ctrl down}w{Ctrl up}, % "ahk_id " hWnd
	}
	oAcc := oChild := ""
	return vRet
}

;==================================================

Code: Select all

;==================================================

;Chrome functions suite (tested on Chrome v77):

;requires Acc.ahk:
;Acc library (MSAA) and AccViewer download links - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=26201

;JEE_ChromeAccInit(vValue)
;JEE_ChromeGetUrl(hWnd:="", vOpt:="")
;JEE_ChromeGetTabCount(hWnd:="")
;JEE_ChromeGetTabNames(hWnd:="", vSep:="`n")
;JEE_ChromeFocusTabByNum(hWnd:="", vNum:="")
;JEE_ChromeFocusTabByName(hWnd:="", vTitle:="", vNum:="")
;JEE_ChromeGetFocusedTabNum(hWnd:="")
;JEE_ChromeAddressBarIsFoc(hWnd:="")
;JEE_ChromeCloseOtherTabs(hWnd:="", vOpt:="", vNum:="")

;note: you can only get the url for the *active* tab via Acc,
;to get the urls for other tabs, you could use a browser extension, see:
;Firefox/Chrome: copy titles/urls to the clipboard - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=22&t=66246

;==================================================

;note: these Acc paths often change:
;Acc paths determined via:
;[JEE_AccGetTextAll function]
;Acc: get text from all window/control elements - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=40615

JEE_ChromeAccInit(vValue)
{
	if (vValue = "U1")
		return "4.1.2.1.2.5.2" ;address bar
	if (vValue = "U2")
		return "4.1.2.2.2.5.2" ;address bar
	if (vValue = "T")
		return "4.1.2.1.1.1" ;tabs (append '.1' to get the first tab)
}

;==================================================

JEE_ChromeGetUrl(hWnd:="", vOpt:="")
{
	local
	static vAccPath1 := JEE_ChromeAccInit("U1")
	static vAccPath2 := JEE_ChromeAccInit("U2")
	if (hWnd = "")
		hWnd := WinExist("A")
	oAcc := Acc_Get("Object", vAccPath1, 0, "ahk_id " hWnd)
	if !IsObject(oAcc)
	|| !(oAcc.accName(0) = "Address and search bar")
		oAcc := Acc_Get("Object", vAccPath2, 0, "ahk_id " hWnd)
	vUrl := oAcc.accValue(0)
	oAcc := ""

	if InStr(vOpt, "x")
	{
		if !(vUrl = "") && !InStr(vUrl, "://")
			vUrl := "http://" vUrl
	}
	return vUrl
}

;==================================================

JEE_ChromeGetTabCount(hWnd:="")
{
	local
	static vAccPath := JEE_ChromeAccInit("T")
	if (hWnd = "")
		hWnd := WinExist("A")
	oAcc := Acc_Get("Object", vAccPath, 0, "ahk_id " hWnd)
	vCount := 0
	for _, oChild in Acc_Children(oAcc)
	{
		;ROLE_SYSTEM_PUSHBUTTON := 0x2B
		if (oChild.accRole(0) = 0x2B)
			continue
		vCount++
	}
	oAcc := oChild := ""
	return vCount
}

;==================================================

JEE_ChromeGetTabNames(hWnd:="", vSep:="`n")
{
	local
	static vAccPath := JEE_ChromeAccInit("T")
	if (hWnd = "")
		hWnd := WinExist("A")
	oAcc := Acc_Get("Object", vAccPath, 0, "ahk_id " hWnd)

	vHasSep := !(vSep = "")
	if vHasSep
		vOutput := ""
	else
		oOutput := []
	for _, oChild in Acc_Children(oAcc)
	{
		;ROLE_SYSTEM_PUSHBUTTON := 0x2B
		if (oChild.accRole(0) = 0x2B)
			continue
		try vTabText := oChild.accName(0)
		catch
			vTabText := ""
		if vHasSep
			vOutput .= vTabText vSep
		else
			oOutput.Push(vTabText)
	}
	oAcc := oChild := ""
	return vHasSep ? SubStr(vOutput, 1, -StrLen(vSep)) : oOutput
}

;==================================================

JEE_ChromeFocusTabByNum(hWnd:="", vNum:="")
{
	local
	static vAccPath := JEE_ChromeAccInit("T")
	if (hWnd = "")
		hWnd := WinExist("A")
	if !vNum
		return
	oAcc := Acc_Get("Object", vAccPath, 0, "ahk_id " hWnd)
	if !Acc_Children(oAcc)[vNum]
		vNum := ""
	else
		Acc_Children(oAcc)[vNum].accDoDefaultAction(0)
	oAcc := ""
	return vNum
}

;==================================================

JEE_ChromeFocusTabByName(hWnd:="", vTitle:="", vNum:="")
{
	local
	static vAccPath := JEE_ChromeAccInit("T")
	if (hWnd = "")
		hWnd := WinExist("A")
	if (vNum = "")
		vNum := 1
	oAcc := Acc_Get("Object", vAccPath, 0, "ahk_id " hWnd)
	vCount := 0, vRet := 0
	for _, 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
}

;==================================================

JEE_ChromeGetFocusedTabNum(hWnd:="")
{
	local
	static vAccPath := JEE_ChromeAccInit("T")
	if (hWnd = "")
		hWnd := WinExist("A")
	oAcc := Acc_Get("Object", vAccPath, 0, "ahk_id " hWnd)
	vRet := 0
	for _, oChild in Acc_Children(oAcc)
	{
		;STATE_SYSTEM_SELECTED := 0x2
		if (oChild.accState(0) & 0x2)
		{
			vRet := A_Index
			break
		}
	}
	oAcc := oChild := ""
	return vRet
}

;==================================================

JEE_ChromeAddressBarIsFoc(hWnd:="")
{
	local
	static vAccPath1 := JEE_ChromeAccInit("U1")
	static vAccPath2 := JEE_ChromeAccInit("U2")
	if (hWnd = "")
		hWnd := WinExist("A")
	oAcc := Acc_Get("Object", vAccPath1, 0, "ahk_id " hWnd)
	if !IsObject(oAcc)
	|| !(oAcc.accName(0) = "Address and search bar")
		oAcc := Acc_Get("Object", vAccPath2, 0, "ahk_id " hWnd)
	;STATE_SYSTEM_FOCUSED := 0x4
	vIsFoc := !!(oAcc.accState(0) & 0x4)
	oAcc := ""
	return vIsFoc
}

;==================================================

;vOpt: L (close tabs to the left)
;vOpt: R (close tabs to the right)
;vOpt: LR (close other tabs)
;vOpt: (blank) (close other tabs)
;vNum: specify a tab other than the focused tab
JEE_ChromeCloseOtherTabs(hWnd:="", vOpt:="", vNum:="")
{
	local
	static vAccPath := JEE_ChromeAccInit("T")
	if (hWnd = "")
		hWnd := WinExist("A")
	if (vNum = "")
		vNum := JEE_ChromeGetFocusedTabNum(hWnd)
	if (vOpt = "")
		vOpt := "LR"
	vDoCloseLeft := !!InStr(vOpt, "L")
	vDoCloseRight := !!InStr(vOpt, "R")

	oAcc := Acc_Get("Object", vAccPath, 0, "ahk_id " hWnd)
	vRet := 0
	oChildren := Acc_Children(oAcc)
	vIndex := oChildren.Length() + 1
	Loop % vIndex - 1
	{
		vIndex--
		oChild := oChildren[vIndex]
		;ROLE_SYSTEM_PUSHBUTTON := 0x2B
		if (oChild.accRole(0) = 0x2B)
			continue
		if (vIndex = vNum)
			continue
		if (vIndex > vNum) && !vDoCloseRight
			continue
		if (vIndex < vNum) && !vDoCloseLeft
			continue
		oChild2 := Acc_Children(oChild).4
		if (oChild2.accName(0) = "Close")
			oChild2.accDoDefaultAction(0)
		oChild2 := ""
	}
	oAcc := oChild := ""
	return vRet
}

;==================================================

Re: Firefox/Chrome, get tab names/focus tab

Posted: 30 Sep 2019, 06:19
by potroveio
Lovely, many thanks, jeeswg! GetTabNum tested and working on Chrome 77 :)

Re: Firefox/Chrome, get tab names/focus tab

Posted: 01 Nov 2019, 19:22
by Conrad
I'm currently using the firefox functions to add media key support in youtube music. However, when I use focustab and ControlSend when firefox is not the active window, it does not send the keystroke to the new tab. It just sends it to the original tab. Here is what I have.

Code: Select all

  
  JEE_FirefoxFocusTabByName(FF, TabName)
  Sleep 200
  ControlSend, ahk_parent, {%Key%}, ahk_class MozillaWindowClass
  JEE_FirefoxFocusTabByName(FF, CurrentTitle)
In this case %Key% is "Space" to play/pause

It works as intended when firefox is the active window. Does anyone know how to fix this?

Re: Firefox/Chrome, get tab names/focus tab

Posted: 17 Jan 2020, 14:08
by ufunk
Hi,

I tried to use the Firefox functions suite from jeeswg's post: https://www.autohotkey.com/boards/viewtopic.php?p=294316#p294316

When I double click on the script nothing happens. I also can't see a hotkey or hotstring to run this script. Please, how can I run this script in a manner that it works?
Because the General test script ("A script I used to test whether the Firefox/Chrome functions were working or not) works from jeeswg's post: https://www.autohotkey.com/boards/viewtopic.php?p=139114#p139114

And I am not shure if I placed the "Acc.ahk" file in the right folder. AHK is installed in the following folder: "C:\Program Files (x86)\AutoHotkey". There was no "Lib" folder there, so I created this "Lib" folder and placed "Acc.ahk" and "Anchor.ahk" there. Was that right? I mean I can use "AccViewer.ahk", so I guess the files are placed in the right folder.

I am using Firefox 72.0.1


Cheers

Re: Firefox/Chrome, get tab names/focus tab

Posted: 21 May 2020, 11:40
by Automator
Hey all, this is my first post. I'm beginner.

I would like to have a function to
#1 copy the name of the active page title in Firefox browser to the clipboard (primary objective)
#2 copy the url of the active page title in Firefox browser to the clipboard

I have tried to implement the code seen here but I saw some errors and I don't understand it. Is there any chance for help and get a working code? I can pay something for your time.

I need:

!F3::
; Launch the function #1
return

Function code #1.

How to implement the library. As ufunk user in previous post I just created "Lib" folder in "C:\Program Files (x86)\AutoHotkey" and placed there "Acc.ahk" and "Anchor.ahk".

+-------------------------------------+

I found a working solution and it's fairly simple (all thanks to this post https://www.autohotkey.com/boards/viewtopic.php?p=275652#p275652):

Code: Select all

!F3::
	
		DetectHiddenWindows, Off			;I don't know whether it's required
		SetTitleMatchMode, 2				;I don't know whether it's required

	If (WinID := WinExist("A"))  				 ;- active window
		{
		WinGetTitle, Title, ahk_id %WinID%		;title of a window or active browser card
		;Clipboard := title

		if title contains Mozilla		;cut Mozilla in the name
  			{
			xxc:=" - Mozilla Firefox"
  			stringreplace,title,title,%xxc%,,all
			}
  		Clipboard:=title
		}

return

Re: Firefox/Chrome, get tab names/focus tab

Posted: 22 May 2020, 19:35
by rommmcek
You can get Url with something like this:

Code: Select all

WinActivate ahk_class MozillaWindowClass
WinWaitActive ahk_class MozillaWindowClass,, 1
if ErrorLevel
    Return
Send, ^l
Clipboard:= ""
While !Clipboard && A_Index <= 5 {
    Sleep 50
    Send ^c
}
Send, {Tab 5}^{home} ; optional attepmpt to focuse site aria

;MsgBox % Clipboard ; Display result

Re: Firefox/Chrome, get tab names/focus tab

Posted: 23 May 2020, 08:53
by Automator
I did it later too, the dumb way :D (F6 focuses on the URL in Firefox) :

Code: Select all

#F3::
	sendinput,{F6}
	Sleep 25
	sendinput,^c
return

Re: Firefox/Chrome, get tab names/focus tab

Posted: 31 Dec 2020, 23:33
by Epialis
I guess I"m completely confused on how to work these. I tried something simple like this and it's always blank

Code: Select all

JEE_ChromeGetUrl(hWnd:="0x1F0726", vOpt:="LR")
I got the hWnd from that little box that popped up to drag the + over the tabs. Sorry for my newbness, just trying to figure this all out.

Blessings.

Re: Firefox/Chrome, get tab names/focus tab

Posted: 01 Jan 2021, 13:08
by rommmcek
Modern browsers evolve very rapidly. Thus this function is obsolete and does not provide the designed functionality anymore.
Try:

Re: Firefox/Chrome, get tab names/focus tab

Posted: 13 Aug 2021, 05:55
by AHKStudent
rommmcek wrote:
01 Jan 2021, 13:08
Modern browsers evolve very rapidly. Thus this function is obsolete and does not provide the designed functionality anymore.
Try:
new path is 4.1.1.1.1.2.5.3
Chrome V. 92

Re: Firefox/Chrome, get tab names/focus tab

Posted: 19 Aug 2021, 17:48
by jwwpua
AHKStudent wrote:
13 Aug 2021, 05:55
new path is 4.1.1.1.1.2.5.3
Chrome V. 92
I'm using a fork of iswitchw.ahk (link: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=89871), and it uses these lines:

Code: Select all

JEE_ChromeAccInit(vValue)
{
	if (vValue = "U1")
		return "4.1.2.1.2.5.2" ;address bar
	if (vValue = "U2")
		return "4.1.2.2.2.5.2" ;address bar
	if (vValue = "T")
		return "4.1.2.1.1.1" ;tabs (append '.1' to get the first tab)
}
Do you know which values U1, U2, and T should be updated to for use with Chrome 92? I'm fairly new to AHK so I'm just trying to figure out how to make Chrome tabs show up in iswitchw. I'm not sure which one should use the new path you mentioned, or what values the other 2 lines need. Thank you!