Limit number of open tabs

A script add-in can close the surplus tabs after opening a new one.

function OnInit(initData) {
    initData.name = 'LimitTabCount';
    initData.version = '2022-07-16';
    initData.url = 'https://resource.dopus.com/t/numbers-of-open-tabs/41730';
    initData.desc = 'Limit number of open tabs';
    initData.default_enable = true;
    initData.min_version = '12.0';
}

function OnOpenTab(openTabData) {
    var tab = openTabData.tab;
    var tabs = tab.right ? tab.lister.tabsright : tab.lister.tabsleft;

    if (tabs.count < 4) return;

    var cmd = DOpus.Create().Command();
    cmd.SetSourceTab(tab);
    cmd.Clear();
    
    for (var i = tabs.count; i > 3; --i) {
        cmd.AddLine('Go TABCLOSE TABPOS=0');
    }

    cmd.Run();
}

EventLimitTabCount.js.txt