1

1. Summary

I can't find, how I can close all tabs in Firefox Quantum without any manual mouse clicks.


2. Details

(Details for preventing XY Problem)

I am working on several projects. I need always opened tabs for different projects (different tabs for different projects).

When I start working on one of my projects, I want automatically and quickly switch between projects: I press hotkey → all current browser tabs close → project-specific tabs open.


3. Requirements

3.1. Types of tabs

These types of tabs also must be closed:

  1. Pinned
  2. Current; browser.tabs.closeWindowWithLastTab key value is false for me

3.2. Methods

Any methods, where user don't need to click manually to specific button are welcome. For example, it would be nice get expected behavior via any free:

  1. Extension or script (for example, written in AutoHotkey), so that I can close all tabs via:

    1. Shortcut
    2. And/or underline access key shortcuts of Firefox menu or context menu
  2. CLI commands

But click to specific buttons in Firefox toolbars is not expected. Reason — I don't find, how I can write the script, that can automatically clicks to specific button (but if you know, how do it, please, make an answer).

3.3. No clicking to specific coordinates

Yes, for example, I can install Close All Tabs Button extension → get x and y coordinates of this extension button → set via AutoHotkey automatically clicking to these coordinates.

But this is not better solution. I can:

  1. Add, remove and move buttons in Firefox toolbar.
  2. Resize Firefox windows.

Coordinates will be shifted in these cases.

3.4. No auto-adding to groups

I tried some Firefox tabs organizers/tabs managers. They have a common non-expected behavior.

I created tab groups of my projects → I added required URLs for each group → I opened any new tabs in browser → this tabs automatically added to one of groups.

I don't need to automatically add random tabs to groups. Groups must contain a specific set of tabs; adding, editing and removing tabs of groups must be solely manually in my case.

3.5. Stay in current Firefox profile

I can programmatically close Firefox → then open new Firefox instance with specific tabs as this:

firefox -P "SashaChernykh" --new-tab -url https://KiraGoddess.com --new-tab -url https://KiraGreatest.com

But in this case pinned tabs from previous session will be preserve in new instance.

I can't find, how I can solve this problem. Yes, I can open new tabs use new Firefox profile, but, possibly, it a not good idea. I'll have to configure and update settings, extensions, bookmarks and so on for each profile. Its additional work, whereas one profile is enough for me.

It would be nice close all tabs, stay in current Firefox profile.


4. Not helped

4.1. Close all tabs extensions

4.1.1. Doesn't close pinned and current tabs

See 3.1 item, why it not expected.

  1. Close All Tabs
4.1.2. No hotkeys and/or menu items

See 3.2 item, why it not expected.

  1. Close All Tabs Button
4.1.3. Both

Both problems: Doesn't close pinned and current tabs and No hotkeys and/or menu items.

  1. Tab Closer
  2. Close All Tabs Button

4.2. Tabs organizers

4.2.1. Non-free
  1. Toast
  2. Workona
4.2.2. Auto-adding to groups

I described this problem in 3.4 item.

  1. Simple Tab Groups
  2. Tab Workspaces
  3. Tab Manager
  4. Power Tabs
  5. Panorama Tab Groups
  6. Tab Manager Plus for Firefox
  7. Conex
  8. Tab Group Switch
4.2.3. No hotkeys

Use these extensions, I can close all previous tabs and open new; but manual mouse clicks required. See 3.2 item for details.

  1. Group Speed Dial
  2. Tab Stash
10
  • By programatically you mean you'd like to do it from a script? Mar 31, 2020 at 14:42
  • @EduardoTrápani , see 3.2 item of my question. Script — also it would be nice. Thanks. Mar 31, 2020 at 14:43
  • 1
    Sorry if I'm asking something you already said, but, do you want to close all tabs AND leave Firefox core running, as in headless, in the background, or do you want to terminate all Firefox processes, hence closing all tabs, the UI, etc...? If the former, I'm not even sure it's possible with recent versions of Firefox, because the various processes are emmeshed way more closely than they used to be. If the latter, well, all you have to do is press Alt-F4, and Firefox will be history in Task Manager in a matter of seconds (a little bit more, actually, since it writes to disk before that).
    – user1019780
    Mar 31, 2020 at 14:47
  • @Didier , I want to close all tabs, that currently opened and then open other tabs (I know, what I need, that open specific tabs. See details in item 2 of my question. Firefox window shouldn't be closed; tabs solely. Thanks for the question. Mar 31, 2020 at 14:54
  • Is closing Firefox and its present set of tabs, to start it again with a fresh set of (different) tabs an option?
    – user1019780
    Mar 31, 2020 at 15:16

1 Answer 1

1

This AHK script works for me on firefox 74.0 (64-Bit), provided that the option "Show tab previews in the Windows taskbar" in firefox Settings is enabled:

#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%
DetectHiddenWindows, On

#IfWinActive ahk_exe firefox.exe  ; only if firefox is the active window

    F1::
    title1 := ""      ; empty var
    title2 := ""
    title3 := ""    

    ; Close all but the active tab:
    WinGetTitle, title1, A
    WinGet, id, list, ahk_class MozillaTaskbarPreviewClass
    Loop, %id%
    {   
        this_ID := id%A_Index%  
        WinGetTitle, title2, ahk_id %this_ID%
        If (title2 != title1)
            WinClose, ahk_id %this_ID%
    }

    ; Close the active tab as soon as another tab gets active:
    SetTimer, CloseActiveTab, 1000  
    return

#IfWinActive

CloseActiveTab: 
If WinActive("ahk_exe firefox.exe")
{
    WinGetTitle, title3, A  
    If (title3 != title1)
    {
        SetTimer, CloseActiveTab, off       
        WinClose, %title1% ahk_class MozillaTaskbarPreviewClass
    }
}
return

EDIT:

Replace pseudo-array to object-based array in your modified script:

DetectHiddenWindows 1
WinActivate ahk_exe firefox.exe

~c & ~f::
Array := []
WinGet, KiraTabsNumber, List, ahk_class MozillaTaskbarPreviewClass
Loop %KiraTabsNumber% {
    Array.Push(KiraTabsNumber%A_Index%)
}
for index, element in Array
    WinClose ahk_id %element%
return
8
  • GEV, please, can you replace pseudo-array to object-based array? For example, on line 36 of my modified script. Because pseudo-arrays not recommended to use. Thanks. Apr 1, 2020 at 17:35
  • Your code closes the program but not all pinned tabs on my Firefox 74.0. Is that what you want to do? In that case you don't need to pusch elements in an array or a timer.
    – Relax
    Apr 1, 2020 at 19:01
  • user3419297, Your code closes the program but not all pinned tabsno, if modify Firefox settings. See line 6 of my modification of your script or 3.1.2 item of my question. Thanks. Apr 1, 2020 at 19:19
  • 1
    See EDIT in this answer.
    – Relax
    Apr 2, 2020 at 15:51
  • I'm sorry, (KiraTabsNumber%A_Index%) — is this definitely not an anti-pattern? Thanks. Apr 2, 2020 at 16:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .