How to avoid creating multiple tabs for a single (tree)folder?

Up front: I am sorry, this has probably been covered before already. I have been searching for an hour or so, but probably been overlooking the answer.

I was going back and forth organizing/deleting folders within a single folder (single folder in the folder tree, to be exact). In this process I noticed that each time a new tab was created, probably because I selected a sub folder, deleted it, and returned into the same same folder (in the folder tree, for example d:\temp).

After a while there were 13(!) tabs, all basically showing the same folder contents from that 1 folder in the tree (e.g.13x d:\temp)

Have vainly been looking for a trick that avoids this. Am sure there is one though.

Any suggestions?

Thanks!

Perhaps something like this add in script?:
DeDuplicateTabs: Auto-close duplicate tabs when new windows open

I'm not certain if that would trigger if the duplicate tab is the result of changing directories, but it could probably be modified to watch an additional event handler if not.

Thanks a lot. Much appreciated your trying to find a solution. The other thread shows that apparently I am not the only one having this issue. Hopefully, one day, Opus has a built in feature that 'solves' this matter.
Thanks again.

I mean does the script work? The point of all the scripting features in Opus is so there isn't a need to build in features for every single person's use case. And this definitely would be something achievable by an add in script.

Edit: Actually looks like the other script doesn't do what you're looking for, but I whipped this one up with the help of AI, so it works but might not be the most efficient or elegant way to do it:

InactiveTabDeduplicator.opusscriptinstall (1.4 KB)

The source code:

function OnInit(initData)
{
    initData.name = "Inactive Tab Deduplicator";
    initData.version = "1.0";
    initData.copyright = "ThioJoe";
    initData.desc = "Automatically closes duplicate folder tabs when non-active tabs change.";
    initData.default_enable = true;
    initData.min_version = "12.22";
}

function OnAfterFolderChange(afterFolderChangeData) {
    //DOpus.Output("OnAfterFolderChange triggered");
    //DOpus.Output("Tab visible: " + afterFolderChangeData.tab.visible);
    //DOpus.Output("Tab path: " + afterFolderChangeData.tab.path);
    
    if (afterFolderChangeData.tab.visible === false) {
    	handleTabChange(afterFolderChangeData.tab.lister, afterFolderChangeData.tab);
	}
}

function handleTabChange(lister, changedTab) {
    //DOpus.Output("handleTabChange called");
    var cmd = DOpus.Create.Command();
    
    //DOpus.Output("Searching for duplicate tabs");
    var activeTabIndex = findActiveTabIndex(lister);
    var duplicateInfo = findDuplicateTabs(lister);
    
    if (duplicateInfo.size > 0) {
        //DOpus.Output("Duplicate tabs found");
        closeDuplicateTabs(cmd, duplicateInfo, activeTabIndex);
    }
}

function findActiveTabIndex(lister) {
    var allTabs = lister.tabs;
    for (var i = 0; i < allTabs.count; i++) {
        if (allTabs(i).visible) {
            //DOpus.Output("Active tab index: " + i);
            return i;
        }
    }
    //DOpus.Output("No active tab found");
    return -1;
}

function findDuplicateTabs(lister) {
    //DOpus.Output("findDuplicateTabs called");
    var allTabs = lister.tabs;
    var mapPaths = DOpus.Create.Map();

    //DOpus.Output("Total number of tabs: " + allTabs.count);

    for (var i = 0; i < allTabs.count; i++) {
        var tab = allTabs(i);
        var path = tab.path;
        //DOpus.Output("Checking tab " + i + ": " + path + ", Visible: " + tab.visible);
        
        if (!mapPaths.exists(path)) {
            mapPaths(path) = DOpus.Create.Vector();
        }
        mapPaths(path).push_back(i);
    }

    var duplicateInfo = DOpus.Create.Map();
    for (var e = new Enumerator(mapPaths); !e.atEnd(); e.moveNext()) {
        var path = e.item();
        if (mapPaths(path).size > 1) {
            duplicateInfo(path) = mapPaths(path);
            //DOpus.Output("Duplicate found for path: " + path + ", Count: " + mapPaths(path).size);
        }
    }

    return duplicateInfo;
}

function closeDuplicateTabs(cmd, duplicateInfo, activeTabIndex) {
    for (var e = new Enumerator(duplicateInfo); !e.atEnd(); e.moveNext()) {
        var path = e.item();
        var tabIndices = duplicateInfo(path);
        //DOpus.Output("Processing duplicates for path: " + path);
        
        var closedCount = 0;
        for (var i = 0; i < tabIndices.size; i++) {
            if (tabIndices(i) !== activeTabIndex) {
                //DOpus.Output("Closing tab at index: " + tabIndices(i));
                cmd.AddLine("Go TABCLOSE TABPOS=" + tabIndices(i));
                closedCount++;
                if (closedCount === tabIndices.size - 1) {
                    break; // Keep at least one tab open
                }
            }
        }
    }
    
    //DOpus.Output("Executing tab close commands");
    cmd.Run();
}