The script add-in TabAppendDriveLabel appends the label of the drive that is displayed in a tab to the tab name if it detects the drive as removable (e.g. a thumb drive) or external (e.g. external HDD). In all other cases, the tab name remains unchanged.
How to setup and use
Save EventTabAppendDriveLabel.js.txt to
%appdata%\GPSoftware\Directory Opus\Script AddIns
Edit the list of internal drives.
While identifying removable drives is very easy, properly detecting external drives is not trivial. That's why the script contains a hard coded list of internal drives that needs to be adjusted to your system. Edit the following line in the script:
var internalDrives = 'CDEFGH';
Things you might enjoy reading
How to use buttons and scripts from this forum
Tab-Labelizer
The script's inner workings
JScript
function OnInit(initData) {
initData.name = 'TabAppendDriveLabel';
initData.version = '2023-07-05';
initData.url = 'https://resource.dopus.com/t/tabappenddrivelabel-show-drive-labels-in-tabs/44916';
initData.desc = '';
initData.default_enable = true;
initData.min_version = '12.0';
}
function OnAfterFolderChange(afterFolderChangeData) {
if (!afterFolderChangeData.result) return;
var cmd = DOpus.Create().Command();
var tab = afterFolderChangeData.tab;
cmd.SetSourceTab(tab);
cmd.RunCommand('Go TABNAME');
tab.Update();
var tabDrive = GetDriveFromTab(tab);
if (!tabDrive) return; // E.g. node 'This PC'
if (tabDrive.type == 'removable' || (tabDrive.type == 'fixed' && !IsInternalDrive(tabDrive))) {
cmd.RunCommand('Go TABNAME="' + tab.displayed_label + ' [' + tabDrive.label + ']"');
}
}
function GetDriveFromTab(tab) {
var tabDrive = tab.path.Split()(0);
var allDrives = DOpus.FSUtil().Drives();
var d = -1;
for (var i = 0; i < allDrives.count; i++) {
if (allDrives(i) == tabDrive) d = i;
}
return d < 0 ? false : allDrives(d);
}
function IsInternalDrive(object) {
var internalDrives = 'CDEFGH'; // list letters of drives that should always be excluded
var tmp = String(object);
if (tmp.substring(1, 3) != ':\\') return false;
if (internalDrives.indexOf(tmp.substring(0, 1).toUpperCase()) < 0) return false;
return true;
}