4

I have 20 different tabs I'd like to be able to open by simply hitting Ctrl+A

The following works for the first 9 tabs, but not beyond that

#SingleInstance, Force
#IfWinActive, ahk_exe chrome.exe
^a::Send, ^2

So I read I'm supposed to use WinActivate

I can get WinActivate to work with programs like notepad, but not with Chrome tabs. Any ideas?

^a::
SetTitleMatchMode, 2
IfWinExist, Twitter ahk_class Chrome_WidgetWin_1
  WinActivate
Stevoisiak
  • 23,794
  • 27
  • 122
  • 225
user3411784
  • 43
  • 1
  • 5
  • are you sure that `IfWinExist, Twitter ahk_class Chrome_WidgetWin_1` is a valid statement? I think you can only state EITHER a window title or an ahk class. – phil294 Jan 06 '17 at 17:07
  • thanks for trying, no I'm not sure it's a valid statement. i've done a bit of research and apparently my idea to make a hotkey for more than 9 tabs is impossible! so now i am experimenting with different chrome/firefox user profiles to group my tabs, then using ctrl+1 thorugh ctrl+9 for each profile – user3411784 Jan 06 '17 at 22:19
  • 1
    A Chrome tab is not a window. In other words, Chrome only exposes the active tab as a window. Ergo, `WinActivate` for inactive tabs will not work since you can't find them in the window list. I think you're out of luck with AHK. You could [write your own Chrome extension](https://developer.chrome.com/extensions/tabs#property-Tab-highlighted), though. Or maybe there already exists one that does what you need. – MCL Jan 09 '17 at 13:39
  • thank you! yes i actually figured that out finally. i'm looking into the imacros extension with firefox/batch script and javascript but not sure if that would work either. – user3411784 Jan 14 '17 at 19:22

1 Answers1

2

I have been working on functions to achieve this functionality for a while. I have completed this project just now, and have a script that should achieve the functionality you require.

Note: depending on changes to Firefox and Chrome, these scripts can break at any time, as have previous attempts at manipulating Firefox tabs, however do check the AutoHotkey forums for updates, and/or the following link:

Firefox/Chrome, get tab names/focus tab - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26947&p=126248#p126248

Note: this script requires the Acc library to run, see the link:

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

GroupAdd, vGroupFirefoxAndChrome, ahk_class MozillaWindowClass
GroupAdd, vGroupFirefoxAndChrome, ahk_class Chrome_WidgetWin_1

#IfWinActive, ahk_group vGroupFirefoxAndChrome
^a::
^b::
^c::
^d::
^e::
^f::
^g::
^h::
^i::
^j::
^k::
^l::
^m::
^n::
^o::
^p::
^q::
^r::
^s::
^t::
^u::
^v::
^w::
^x::
^y::
^z::
WinGet, hWnd, ID, A
WinGetClass, vWinClass, ahk_id %hWnd%
vLetter := SubStr(A_ThisHotkey, 1-1)
vNum := Asc(vLetter)-96

if (vWinClass = "MozillaWindowClass")
JEE_FirefoxFocusTabByNum(hWnd, vNum)
if (vWinClass = "Chrome_WidgetWin_1")
JEE_ChromeFocusTabByNum(hWnd, vNum)
Return
#IfWinActive

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

JEE_FirefoxGetTabNames(hWnd, vSep="`n")
{
oAcc := Acc_Get("Object", "4", 0, "ahk_id " hWnd)
Loop, % oAcc.accChildCount
if (oAcc.accName(A_Index) = "Browser tabs")
if (1, oAcc := Acc_Child(oAcc, A_Index))
break
oAcc := Acc_Child(oAcc, 1)

vOutput := ""
Loop, % oAcc.accChildCount
{
vTabText := oAcc.accName(A_Index)
if !(vTabText == "")
;if !(vTabText == "New Tab")
;if !(vTabText == "Open a new tab")
vOutput .= vTabText vSep
}
vOutput := SubStr(vOutput, 1, -StrLen(vSep)) ;trim right

oAcc := ""
Return vOutput
}

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

JEE_FirefoxFocusTabByNum(hWnd, vNum)
{
oAcc := Acc_Get("Object", "4", 0, "ahk_id " hWnd)
Loop, % oAcc.accChildCount
if (oAcc.accName(A_Index) = "Browser tabs")
if (1, oAcc := Acc_Child(oAcc, A_Index))
break
oAcc := Acc_Child(oAcc, 1)

vRet := 0
For each, oChild in Acc_Children(oAcc)
{
if (A_Index = vNum)
if (1, oChild.accDoDefaultAction(0), vRet := A_Index)
break
}

Return vRet
}

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

JEE_FirefoxFocusTabByName(hWnd, vTitle, vNum=1)
{
oAcc := Acc_Get("Object", "4", 0, "ahk_id " hWnd)
Loop, % oAcc.accChildCount
if (oAcc.accName(A_Index) = "Browser tabs")
if (1, oAcc := Acc_Child(oAcc, A_Index))
break
oAcc := Acc_Child(oAcc, 1)

vCount := 0
vRet := 0
For each, oChild in Acc_Children(oAcc)
{
vTabText := oChild.accName(0)
if (vTabText = vTitle)
vCount ++
if (vCount = vNum)
if (1, oChild.accDoDefaultAction(0), vRet := A_Index)
break
}

oAcc := ""
Return vRet
}

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

JEE_ChromeGetTabNames(hWnd, vSep="`n")
{
oAcc := Acc_ObjectFromWindow(hWnd)
oAcc := Acc_Child(oAcc, 1), oAcc := Acc_Child(oAcc, 2)
oAcc := Acc_Child(oAcc, 2), oAcc := Acc_Child(oAcc, 2)

vOutput := ""
For each, oChild in Acc_Children(oAcc)
{
vTabText := Acc_Child(oChild, 1).accName(0)
if !(vTabText == "")
vOutput .= vTabText vSep
}
vOutput := SubStr(vOutput, 1, -StrLen(vSep)) ;trim right

oAcc := ""
Return vOutput
}

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

JEE_ChromeFocusTabByNum(hWnd, vNum)
{
oAcc := Acc_ObjectFromWindow(hWnd)
oAcc := Acc_Child(oAcc, 1), oAcc := Acc_Child(oAcc, 2)
oAcc := Acc_Child(oAcc, 2), oAcc := Acc_Child(oAcc, 2)

vRet := 0
For each, oChild in Acc_Children(oAcc)
{
if (A_Index = vNum+1)
if (1, oChild.accDoDefaultAction(0), vRet := A_Index)
break
}

Return vRet
}

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

JEE_ChromeFocusTabByName(hWnd, vTitle, vNum=1)
{
oAcc := Acc_ObjectFromWindow(hWnd)
oAcc := Acc_Child(oAcc, 1), oAcc := Acc_Child(oAcc, 2)
oAcc := Acc_Child(oAcc, 2), oAcc := Acc_Child(oAcc, 2)

vCount := 0
vRet := 0
For each, oChild in Acc_Children(oAcc)
{
vTabText := oChild.accName(0)
if (vTabText = vTitle)
vCount ++
if (vCount = vNum)
if (1, oChild.accDoDefaultAction(0), vRet := A_Index)
break
}

oAcc := ""
Return vRet
}

;==================================================
vafylec
  • 965
  • 1
  • 6
  • 23