Windows – How to customize each Firefox window icon individually

firefoxiconswindowswindows 10

I'm a tab hoarder and I admit it. But at least I've sorted them into contextual windows now, and I'd love to have different icons for each window in the Windows task bar (not the tab bar, which is governed by the favicons). How can this be achieved?

As an example imagine I have one Window with various StackExchange tabs, for which I would like to have the StackExchange logo as icon, another window with GitHub repos that should have the GitHub logo, and a third window with tabs specific to a project for which I have a custom icon (or just e.g. a coloured letter atop the Firefox logo).

I'd also accept a solution that manages to simply use each window's first tab's favicon, though independence on that would be preferred.

Best Answer

This can be done using the free AutoHotkey.

Create a .ahk text file and enter these contents:

#Persistent
SetTitleMatchMode, 2    ; A window's title to contain the text anywhere

F9::
ChangeWindowIcon("title text", "\path\to\iconfile.ico")

ChangeWindowIcon(WinSpec, IconFile) {
    hIcon := DllCall("LoadImage", uint, 0, str, IconFile, uint, 1, uint, 0, uint, 0, uint, uint 0x10)
    if (!hIcon) {
        MsgBox, "Icon file missing or invalid in `nChangeWindowIcon(" IconFile ", " WinSpec ")`n`n"
        Throw "Icon file missing or invalid in `nChangeWindowIcon(" IconFile ", " WinSpec ")`n`n"
    }
    hWnd := WinExist(WinSpec)
    if (!hWnd) {
        MsgBox, Window Not Found
        return "Window Not Found"
    }
    SendMessage, WM_SETICON:=0x80, ICON_SMALL:=0, hIcon,, ahk_id %hWnd% ; Set the window's small icon
    SendMessage, WM_SETICON:=0x80, ICON_BIG:=1, hIcon,, ahk_id %hWnd%   ; Set the window's big icon
    SendMessage, WM_SETICON:=0x80, ICON_SMALL2:=2, hIcon,, ahk_id %hWnd%    ; Set the window's small icon
}

The script is set to be activated upon hitting F9, but you may set your own key. Add as many calls to the function ChangeWindowIcon as required, each with the parameters of:

  • Unique text that can be found in the title
  • The full address of an icon file

When the script is running, you may right-click its green H icon in the traybar and choose Exit to terminate. If it works, you may also add it to your Startup group to run when you login.

Note that AutoHotkey can also launch your favorite tabs and arrange their layout on the screen. There isn't really much that AutoHotkey cannot do.

Related Question