Script for Tab Naming

Primarily we use a folder naming convention such as this:

z:\files[client][year][subfolders]

I would like each tab to display the "[client]" folder name of the above regardless of what year or [subfolder] i am in. (I can see that from the full file path). I often have many tabs open and want to be able to switch easily between them based only on the client name. The "Z:\files" will be static. If in any other folder, it can use the DO default tab naming.

In plain "english" (dont know coding)....

If Path begins with "z:\files"
rename tab "[client]" (i.e"[client]" is the respective folder name)
else
leave default DO tab name

Give this a try.

function OnInit(initData) {
    initData.name = 'TabRenameToClient';
    initData.version = '2022-09-28';
    initData.url = 'https://resource.dopus.com/t/script-for-tab-naming/42310';
    initData.desc = 'Rename Tab to client folder';
    initData.default_enable = true;
    initData.min_version = '12.0';
}

function OnAfterFolderChange(afterFolderChangeData) {
    if (!afterFolderChangeData.result) return;

    var tab = afterFolderChangeData.tab;
    var vecPath = DOpus.FSUtil().Resolve(tab.path).Split();

    if (vecPath.count < 3) return;
    if (vecPath(0).toLowerCase() != 'z:\\') return;
    if (vecPath(1).toLowerCase() != 'files') return;

    var newTabName = vecPath(2);

    if (newTabName == tab.displayed_label) return;

    var cmd = DOpus.Create().Command();
    cmd.SetSourceTab(tab);
    cmd.RunCommand('Go TABNAME="' + newTabName + '"');
}

EventTabRenameToClient.js.txt