In your Columns example, config parameter is reflected like this:
initData.config.AvgMinSize = "5 MB";
initData.config_desc = DOpus.Create.Map("AvgMinSize", "When calculating average sizes, ignore files smaller than this unless they are the only ones. Bytes unless KB, MB or GB suffix added.")
How would you use initData.config and inti.config_desc with a vector, including options and descriptions?
I have spent way too many hours on this and have yet to figure out how to make this work:
for (var ee = new Enumerator(tabItem.files); !ee.atEnd(); ee.moveNext()) {
var fileItem = ee.item();
if (ftg != true); {
if (!fileItem.InGroup('Programs')) { continue;
extFound = true;
} else
if (fileItem.ext != '.txt') continue;
extFound = true;}
break;
}
It works if I limit to either program or text, but I want to be able to check for the program file type group first. If it comes up empty, then check for .txt extension.
for (var ee = new Enumerator(tabItem.files); !ee.atEnd(); ee.moveNext()) {
var fileItem = ee.item();
if (ftg && !fileItem.InGroup('Programs')) continue;
if (fileItem.ext != '.txt') continue;
extFound = true;
break;
}
Thanks for this @lxp, and thanks @Jon for pointing out that semicolon. Clearly, I need to get better at this, which includes understanding how to use tools like CyberChef and put stuff in the right place.
That said, the code you suggested does not work. I dumbed the function down as much as possible, per @Leo's earlier suggestion:
function OnInit(initData) {
initData.name = 'RecolorTabBasedOnFileExtension';
initData.version = '2023-02-05';
initData.copyright = '';
initData.url = 'https://resource.dopus.com/t/tab-color-based-on-folder-content/43305';
initData.desc = 'Change tab color based on file extensions';
initData.default_enable = true;
initData.min_version = '12.0';
}
function OnOpenLister(openListerData) {
DOpus.Output('*** OnOpenLister');
if (!openListerData.after) return true;
checkFileExtension(openListerData.lister.activetab);
return false;
}
function OnActivateLister(activateListerData) {
DOpus.Output('*** OnActivateLister');
if (!activateListerData.active) return;
checkFileExtension(activateListerData.lister.activetab);
}
function OnOpenTab(openTabData) {
DOpus.Output('*** OnOpenTab');
checkFileExtension(openTabData.tab);
}
function OnActivateTab(activateTabData) {
DOpus.Output('*** OnActivateTab');
checkFileExtension(activateTabData.newtab);
}
function OnSourceDestChange(sourceDestChangeData) {
DOpus.Output('*** OnSourceDestChange');
checkFileExtension(sourceDestChangeData.tab);
}
function OnAfterFolderChange(afterFolderChangeData) {
DOpus.Output('*** OnAfterFolderChange');
checkFileExtension(afterFolderChangeData.tab);
}
function OnDoubleClick(doubleClickData) {
DOpus.Output('*** OnDoubleClick');
checkFileExtension(doubleClickData.tab);
}
function OnDisplayModeChange(displayModeChangeData) {
DOpus.Output('*** OnDisplayModeChange');
checkFileExtension(displayModeChangeData.tab);
}
function OnTabClick(tabClickData) {
DOpus.Output('*** OnTabClick');
checkFileExtension(tabClickData.tab);
}
var cmd = DOpus.Create().Command();
var fsu = DOpus.FSUtil();
function checkFileExtension(tab) {
for (var e = new Enumerator(tab.lister.tabs); !e.atEnd(); e.moveNext()) {
var tabItem = e.item();
var extFound = false;
for (var ee = new Enumerator(tabItem.files); !ee.atEnd(); ee.moveNext()) {
var fileItem = ee.item();
if (!fileItem.InGroup('Programs')) continue;
if (fileItem.ext != '.txt') continue;
extFound = true;
break;
}
cmd.SetSourceTab(tabItem);
if (extFound) {
cmd.RunCommand('Go TABCOLOR=255,128,0');
} else {
cmd.RunCommand('Go TABCOLOR=reset');
}
}
}
If I comment out either if statement, the function works with the other if statement fine. However, with the code as is, the if statements seem to cancel each other out, with no tab color change. Very frustrating.
Besides an inept coder, what might be causing this?
Thanks for pointing that out. It cleared the error. However, for some reason the script seems to ignore the Category selected and focuses strictly on the Extension entered.
The script may be ignoring the Category configured here:
var vecType = DOpus.NewVector();
vecType.push_back(0);
vecType.push_back("FileTypeGroup");
vecType.push_back("Extension");
configName = "Category";
initData.Config[configName] = vecType;
initData.config_desc(configName) = "Select File Type Group or Extension";
initData.config_groups(configName) = "Choices";
And/or it may not be interpreting this correctly:
if (Script.Config["Category"] != 0) {
switch (Script.Config["Group"]) {
case 0: if (!fileItem.InGroup('Archives')) continue;
extFound = true;
break;
case 1: if (!fileItem.InGroup('Databases')) continue;
extFound = true;
break;
case 2: if (!fileItem.InGroup('Documents')) continue;
extFound = true;
break;
case 3: if (!fileItem.InGroup('Images')) continue;
extFound = true;
break;
case 4: if (!fileItem.InGroup('Movies')) continue;
extFound = true;
break;
case 5: if (!fileItem.InGroup('Music')) continue;
extFound = true;
break;
case 6: if (!fileItem.InGroup('Programs')) continue;
extFound = true;
break;
}
Thanks a lot for sharing it.
Please, I did read the post you thankfully attached, but to make sure that I understand the instructions correctly, shall I just rename the file to remove the .txt extension and let it be a .js extension?
and then drop the file into: Preferences>Toolbars>Scripts
Or there is another way?
Thanks