I want to delete specific tabs in Firefox by title contents programmatically.
Any ideas would be great
Many thanx
Delete tab in Firefox using ahk
Re: Delete tab in Firefox using ahk
I never tried this library, but it may be useful. viewtopic.php?p=294316#p294316
Re: Delete tab in Firefox using ahk
Thanx had a look at that post earlier
It seems way beyond me as it seems very version dependent
Will give it another try
Again many thanx
It seems way beyond me as it seems very version dependent
Will give it another try
Again many thanx
-
- Posts: 4391
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Delete tab in Firefox using ahk
This is for you to start:
Code: Select all
if !AccFF := AccObjectFromWindow( hWnd := WinExist("ahk_class MozillaWindowClass") )
throw "Failed to get accessible object from FF"
AccTabList := SearchElement(AccFF, {Role: ROLE_SYSTEM_PAGETABLIST := 0x3C})
WinActivate
Loop % AccTabList.accChildCount() - 1 {
AccTab := AccTabList.accChild(A_Index)
AccTab.accDoDefaultAction(0)
MsgBox, % AccTab.accName(0)
}
SearchElement(parentElement, params)
{
found := true
for k, v in params {
try {
if (k = "State")
(!(parentElement.accState(0) & v) && found := false)
else if (k ~= "^(Name|Value)$")
(!(parentElement["acc" . k](0) ~= v) && found := false)
else if (k = "ChildCount")
(parentElement["acc" . k] != v && found := false)
else
(parentElement["acc" . k](0) != v && found := false)
}
catch
found := false
} until !found
if found
Return parentElement
for k, v in AccChildren(parentElement)
if obj := SearchElement(v, params)
Return obj
}
AccObjectFromWindow(hWnd, idObject = 0) {
static IID_IDispatch := "{00020400-0000-0000-C000-000000000046}"
, IID_IAccessible := "{618736E0-3C3D-11CF-810C-00AA00389B71}"
, OBJID_NATIVEOM := 0xFFFFFFF0, VT_DISPATCH := 9, F_OWNVALUE := 1
, h := DllCall("LoadLibrary", "Str", "oleacc", "Ptr")
VarSetCapacity(IID, 16), idObject &= 0xFFFFFFFF, AccObject := 0
DllCall("ole32\CLSIDFromString", "Str", idObject = OBJID_NATIVEOM ? IID_IDispatch : IID_IAccessible, "Ptr", &IID)
if DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hWnd, "UInt", idObject, "Ptr", &IID, "PtrP", pAcc) = 0
AccObject := ComObject(VT_DISPATCH, pAcc, F_OWNVALUE)
Return AccObject
}
AccChildren(Acc) {
if ComObjType(Acc, "Name") != "IAccessible" {
ErrorLevel := "Invalid IAccessible Object"
Return
}
try childCount := Acc.accChildCount
if !childCount
Return
Children := []
VarSetCapacity(varChildren, childCount*(8 + A_PtrSize*2), 0)
res := DllCall("oleacc\AccessibleChildren", "Ptr", ComObjValue(Acc), "Int", 0
, "Int", childCount, "Ptr", &varChildren, "IntP", childCount)
if (res != 0) {
ErrorLevel := "winapi AccessibleChildren failed"
Return
}
Loop % childCount {
offset := (A_Index - 1)*(A_PtrSize*2 + 8)
_child := NumGet(varChildren, offset + 8)
if NumGet(varChildren, offset) != (VT_DISPATCH := 9)
child := _child
else
child := AccQuery(_child), ObjRelease(_child)
Children.Push(child)
}
Return Children
}
AccQuery(Acc) {
static IAccessible := "{618736e0-3c3d-11cf-810c-00aa00389b71}", VT_DISPATCH := 9, F_OWNVALUE := 1
try Return ComObject(VT_DISPATCH, ComObjQuery(Acc, IAccessible), F_OWNVALUE)
}
Re: Delete tab in Firefox using ahk
Another example is below. I had not seen teadrinker's earlier post.
Code: Select all
#Include d:\utils\acc\Acc.ahk ; https://www.autohotkey.com/boards/viewtopic.php?t=40590
#Include d:\utils\firefoxLib.ahk ; https://www.autohotkey.com/boards/viewtopic.php?p=294316#p294316
closeTabs("AutoHotkey")
closeTabs(name) { ; Close Firefox tabs
If !hWnd := WinExist("ahk_exe firefox.exe")
Return
tab := []
For each, tabName in StrSplit(JEE_FirefoxGetTabNames(hWnd), "`n") {
If !Instr(tabname, name)
Continue
JEE_FirefoxFocusTabByName(hWnd, tabName)
Sleep, 500
ControlSend, ahk_parent, {Ctrl down}w{Ctrl up}, ahk_id %hWnd%
}
}
Re: Delete tab in Firefox using ahk
thanx will give it a try
Re: Delete tab in Firefox using ahk
Sorry for my ignorance
I saved the firefox file -first line starting with ";Firefox functions suite (tested on Firefox v69):"
as firefoxlib.ahk --Is that correct?
I cannot find firefoxlib.ahk in above board post#Include d:\utils\firefoxLib.ahk ; viewtopic.php?p=294316#p294316
I saved the firefox file -first line starting with ";Firefox functions suite (tested on Firefox v69):"
as firefoxlib.ahk --Is that correct?
Last edited by smbs on 28 Nov 2021, 07:35, edited 1 time in total.
Re: Delete tab in Firefox using ahk
@ tea drinker
Many thanx but your script is way beyond me but works great!
however once we loop thru tab names AccTab.accName(0)
I want to delete certain tabs which contain a specific word or words
How can this be done?
many thanx
Many thanx but your script is way beyond me but works great!
however once we loop thru tab names AccTab.accName(0)
I want to delete certain tabs which contain a specific word or words
How can this be done?
many thanx
Re: Delete tab in Firefox using ahk
The Firefox library is the script that is posted at the other site. I happened to name it firefoxLib.ahk on my computer.
-
- Posts: 4391
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Delete tab in Firefox using ahk
You need to change the Loop like this:
Code: Select all
wordToClose := "AutoHotkey"
Loop % AccTabList.accChildCount() - 1 {
AccTab := AccTabList.accChild(A_Index)
if InStr(AccTab.accName(0), wordToClose) {
AccTab.accDoDefaultAction(0) ; switch to the tab containing %wordToClose%
Send ^w ; close that tab
break
}
}
Re: Delete tab in Firefox using ahk
@Mickeyww
I saved the firefox file -first line starting with ";Firefox functions suite (tested on Firefox v69):"
as firefoxlib.ahk --Is that correct?
I saved the firefox file -first line starting with ";Firefox functions suite (tested on Firefox v69):"
as firefoxlib.ahk --Is that correct?
Re: Delete tab in Firefox using ahk
@teadrinker
Many thanx works great Really learnt something!
Many thanx works great Really learnt something!
Re: Delete tab in Firefox using ahk
smbs: Yes.
Re: Delete tab in Firefox using ahk
@mikeyww
Have you tested it? It doesn't work for me--just exits without error
using FF version 94.0.2 (64-bit)
Many thanx again
Have you tested it? It doesn't work for me--just exits without error
using FF version 94.0.2 (64-bit)
Many thanx again
Re: Delete tab in Firefox using ahk
Indeed, I tested the script that I posted before posting it.
Feel free to post your script for feedback about it.
Feel free to post your script for feedback about it.
Re: Delete tab in Firefox using ahk
@mikeyww
Got it working
Many thanx for your help and patience!!
Got it working
Many thanx for your help and patience!!
Re: Delete tab in Firefox using ahk
@mikeyww
BTW , using your script, if there is a "PIP" tab -picture in picture the tab is not found and is overlooked --might be a bug in library file
Drink tea's solution works great in all cases.
Just for your interest
Regards
BTW , using your script, if there is a "PIP" tab -picture in picture the tab is not found and is overlooked --might be a bug in library file
Drink tea's solution works great in all cases.
Just for your interest
Regards
Re: Delete tab in Firefox using ahk
Thanks for letting me know. By all means, I'm on board with drinking tea as an approach of first choice.
Re: Delete tab in Firefox using ahk
@teadrinker
I have an additional request if you have the patience.
As FF supports multiple PIPS therefore
In FF I would like to close only tabs which are not showing in "picture in picture" mode.
A tab in FF playing a stream has "playing" below tab name.
A tab in FF playing a stream in "Picture in picture" mode has "Picture-in-Picture" below tab name.
Is there a way to differentiate between these 2 types of tabs?
Many thanx
I have an additional request if you have the patience.
As FF supports multiple PIPS therefore
In FF I would like to close only tabs which are not showing in "picture in picture" mode.
A tab in FF playing a stream has "playing" below tab name.
A tab in FF playing a stream in "Picture in picture" mode has "Picture-in-Picture" below tab name.
Is there a way to differentiate between these 2 types of tabs?
Many thanx