Get tab depth via script

Goal: have button with label indicating active tab path depth.

Assumption: I need to use tab.path.components in a script to get the number, then have a button that leverages @label to reference the script for the active tab.

Is this logic sound?

Trying to build a simple script to output the number but not receiving any output. Here's the script:

function OnInit(initData)
{
	initData.name = "TabDepth";
	initData.version = "1.0";
	initData.copyright = "(c) 2025 Chuck";
//	initData.url = "https://resource.dopus.com/c/buttons-scripts/16";
	initData.desc = "";
	initData.default_enable = true;
	initData.min_version = "13.0";
}

function OnAfterFolderChange(afterFolderChangeData)
{
	var currenttab = OpenListerData.lister.activetab;
	var td = tab.path.components;
	DOpus.Output("Tab Depth = " + td);
}

What am I missing?

What is OpenListerData ?

Treat yourself to some Evaluator goodness:

@label:=Count(source)
2 Likes

That's my poor interpretation of another script that I thought would prove helpful. While I follow and try to learn from talented people like you in this forum, I sometimes miss the mark.

I missed the forest from the trees. Thanks, as always!

I originally started down the "let's add this to the tab name via script" road, with the intent to add this as an option to this script:

Summary
function OnInit(initData) {
    initData.name = 'RenameTabItemCount';
    initData.version = '2022-12-30';
    initData.copyright = '';
    initData.url = 'https://resource.dopus.com/t/item-count-in-tab-name/43276';
    initData.desc = 'Show number of items in folder tab';
    initData.default_enable = true;
    initData.min_version = '12.0';
}

function OnOpenLister(openListerData) {
//    DOpus.Output('*** OnOpenLister');
    if (!openListerData.after) return true;
    AppendItemCount(openListerData.lister.activetab);
    return false;
}

function OnActivateLister(activateListerData) {
//    DOpus.Output('*** OnActivateLister');
    if (!activateListerData.active) return;
    AppendItemCount(activateListerData.lister.activetab);
}

function OnOpenTab(openTabData) {
//    DOpus.Output('*** OnOpenTab');
    AppendItemCount(openTabData.tab);
}

function OnActivateTab(activateTabData) {
//    DOpus.Output('*** OnActivateTab');
    AppendItemCount(activateTabData.newtab);
}

function OnSourceDestChange(sourceDestChangeData) {
//    DOpus.Output('*** OnSourceDestChange');
    AppendItemCount(sourceDestChangeData.tab);
}

function OnAfterFolderChange(afterFolderChangeData) {
//    DOpus.Output('*** OnAfterFolderChange');
	AppendItemCount(afterFolderChangeData.tab);
}

function OnDoubleClick(doubleClickData) {
//    DOpus.Output('*** OnDoubleClick');
    AppendItemCount(doubleClickData.tab);
}

function OnDisplayModeChange(displayModeChangeData) {
//    DOpus.Output('*** OnDisplayModeChange');
    AppendItemCount(displayModeChangeData.tab);
}

function OnTabClick(tabClickData) {
//    DOpus.Output('*** OnTabClick');
    AppendItemCount(tabClickData.tab);
}

var cmd = DOpus.Create().Command();
var fsu = DOpus.FSUtil();

function AppendItemCount(tab) {
    for (var e = new Enumerator(tab.lister.tabs); !e.atEnd(); e.moveNext()) {
        var tabItem = e.item();

//       DOpus.Output('tabItem.path: "' + tabItem.path + '"');

        var tabPath = String(tabItem.path);
        if (tabPath == '') continue;

        tabPath = fsu.Resolve(tabPath);

        var tabName = String(tabPath);

        if (tabName.substring(0, 2) == '::' || tabName.substring(0, 5) == 'coll:' || tabName.substring(0, 4) == 'ftp:') {
            tabName = fsu.DisplayName(tabPath);
        } else {
            if (tabName.slice(-1) == '\\') {
                var tabName = tabName.substring(0, 2);
            } else {
                var tabName = tabPath.filepart;
            }
        }

        var c = tabItem.all.count;
        var newTabName = tabName + (c > 0 ? (' (' + c + ')') : '');
        if (newTabName == tabItem.displayed_label) continue;

        cmd.SetSourceTab(tabItem);
        cmd.RunCommand('Go TABNAME="' + newTabName + '"');
    }
}

That said and circling back to scripting, how would one get the depth via script?

Try

function OnInit(initData) {
    initData.name = 'TabDepth';
    initData.default_enable = true;
}

function OnAfterFolderChange(afterFolderChangeData) {
    var currenttab = afterFolderChangeData.tab;
    var td = currenttab.path.components;
    DOpus.Output('Tab Depth = ' + td);
}

See also here.

1 Like

Thank you!