Hi
I've been looking for a way to possibly do this and I found a few scripts that date back many years so I thought I ask about the latest Dopus 13.
What I'd like to do it create a menu of the Predefined Filters.
I can pretty easily create a menu and then add each filter to it using a specific command such as
Select "Binaries" FILTER FILTERFLAGS=hidenomatch
And that works, but of course, every time I change the predefined filters, I have to go and edit the menu.
I know that creating menus from things like folder content is trivial, I use something like this
Go C:\dev\.go FOLDERCONTENT="filefilter=*.(exe|txt|lnk|config|bat),dblclickmenu"
or like this for Favorites
Favorites SHOWICONS USEQUALKEYS NOOPENINTABS
to autopopulate menus in several places and it works a treat.
But I haven't found a way to do similar for predefined filters.
Is something like that possible? Or is it one of those things that requires a script?
Building dynamic menus (like the GO FOLDERCONTENT example you gave) from scripting is not currently doable.
But building sort of a customized context menu is (which can appear when you click on a button), and the commands triggered from that menu can be configurable.
This requires scripting.
For filters though, the main thing that seems to be missing is a way to retrieve the list of filters names from the configuration. I couldn't find anything in the scripting reference that would allow for searching for the current filters.
There is a Filter object. You can even "load" the definition from a user defined filter (using its name), but I can't find a way to iterate through all defined filters to get them (or at least their name).
Could be a feature request that a way is given in scripting interface to retrieve all user defined filters.
Thanks, this can be considered as a workaround.
But it would be definitely be cleaner if this could be retrieved through the scripting interface (as TabGroups or favorites or aliases for example).
At least, it would just be about reading the filenames, not their content.
// PopupSelectPresets
// (c) 2025 Stephane
// This is a script for Directory Opus.
// See https://www.gpsoft.com.au/endpoints/redirect.php?page=scripts for development information.
// Called by Directory Opus to initialize the script
function OnInit(initData)
{
initData.name = "PopupSelectPresets";
initData.version = "1.0";
initData.copyright = "(c) 2025 Stephane";
// initData.url = "https://resource.dopus.com/c/buttons-scripts/16";
initData.desc = "";
initData.group = 'Commands';
initData.default_enable = true;
initData.min_version = "13.0";
// Add a command to Opus
var cmd = initData.AddCommand();
cmd.name = 'PopupSelectPresets'; // command name
cmd.method = "OnPopupSelectPresets"; // function called
cmd.desc = initData.desc;
cmd.label = initData.name; // name shown in commands list in customize dialog
cmd.noprogress = true;
}
function OnPopupSelectPresets(scriptCmdData) {
// First, we retieve all user defined filters names
var filterNames = DOpus.Create.Vector();
var dirIter = DOpus.FSUtil.ReadDir('/dopusdata/Filters');
while(!dirIter.complete) {
var item = dirIter.next();
if (item.is_dir) continue;
if (item.ext != ".ofi") continue;
filterNames.push_back(item.name_stem);
dout("Adding:" + item.name_stem);
}
// vectors for passing to dialog object and command object
var menu_items = DOpus.Create.Vector();
var menu_commands = DOpus.Create.Vector();
var index = 0;
for (var e = new Enumerator(filterNames); !e.atEnd(); e.moveNext())
{
menu_items(index) = "â–¶ Select with preset \t\t'" + e.item() + "'";
menu_commands(index) = 'Select "' + e.item() + '" FILTER FILTERFLAGS=hidenomatch';
index++;
}
// show popup list
var cmd = scriptCmdData.func.command;
var dlg = scriptCmdData.func.Dlg;
dlg.choices = menu_items;
dlg.menu = 0;
dlg.Show();
// run command
if (dlg.result && menu_commands[dlg.result - 1] != 'separator')
cmd.RunCommand(menu_commands[dlg.result - 1]);
}
// Helper dout function
function dout(msg, error, time) {
if (error == undefined) error = false;
if (time == undefined) time = true;
DOpus.output(msg, error, time);
}
And then make a standard Opus button calling: PopupSelectPresets
Pretty much (I'm not familiar with this syntax).
The only differences I see are:
Your proposition is closer to the initial request (having something in the likes of the Go FOLDERCONTENT) that you can put in a menu, where the script will open a popup with the list of filters.
That syntax does not seem to display the name of the preset, you'd need to hover the icon (might be related to some configuration on my side).
Note: I also have a presets.dup in that folder which is not an ".ofi" file, which I could filter within the script. I can't say if it's normal and I can't say if your syntax allows for such kind of filtering.
EDIT: The filters in the presets.dup seem to be the filters marked as favorites in the filter section of the Find panel.
I can config a button with drop down menu, it drops down and shows the preconfigured filters and picking one works great.
BUT, if I pick another filter, it appears to "append" the second filter to the filter already in place.
I can see some good uses for that, but for what I want, it'd prefer to "clear all filters" and THEN apply the selected filter.
I've tried something like this
Go /dopusdata\Filters FOLDERCONTENT="nodirs,filefilter=*.ofi"
[
Set CLEARFILTERS
Select "{filepath|noext}" FILTER FILTERFLAGS=hidenomatch
]
But it didn't change the behavior, Tried various iteration so Select NONE or HIDE, HIDEUNSEL, etc and couldn't make any headway.
I'm just wondering if multiple embedded commands like this are even supported? I couldn't find hardly anything in the docs about embedded commands for the GO FOLDERCONTENT command.....
command that would, essentially, clear all filters and only apply the single specified filter?
I'd rather not have to remember to manually clear the filter when clicking the filter menu item...
Solved it
There's a little bit of "screen flash" but, for this purposes it's ok.
Create a Menu Button, put a button inside it, then put this in the Button's command
Go /dopusdata\Filters FOLDERCONTENT="nodirs,filefilter=*.ofi"
[
Set SHOWEVERYTHING=off
Set SHOWEVERYTHING=on
Select "{filepath|noext}" FILTER FILTERFLAGS=hidenomatch
]
Multiple commands ARE supported for embedded commands. i just didn't have the right one.
Had to play with it a bit.
Just setting the Show everything to on didn't work. Had to set it OFF and then back ON. and THEN apply the filter.
We'll add a FILTERFLAGS=showhidden in the next beta to handle this better.
I would not depend on Set SHOWEVERYTHING=on before doing the filter as that may not continue to work. It puts you into a weird state where you're both filtering what's shown and in Show Everything mode, which is actually a bug and won't work that way if we fix it.
Is there are reason you didn't go with Jon's suggestion of Select FILTER=list and continued using Go FOLDERCONTENT to build the list instead? You should be able to do everything more cleanly with a single-line command that just uses Select. (At least once the next beta is out with the extra FILTERFLAGS functionality.)