Save and restore QuickFilter settings

This add-in saves and restores the quickfilter settings per folder when navigating in a tab. It's useful if you don't want to keep a quickfilter in a newly opened folder (Preferences / File Displays / FAYT and Filter Bar Options / Clear Quick filter automatically when changing folders), but like to automatically restore a quickfilter when coming back to a previously used folder.

The quickfilter definitions are stored with the tab, so they won't affect folders in other tabs and they will be gone once the tab is closed.

function OnInit(initData) { = 'SaveQuickFilter';
    initData.version = '2023-02-19';
    initData.copyright = '';
    initData.url = '';
    initData.desc = 'Save and restore QuickFilter settings';
    initData.default_enable = true;
    initData.min_version = '12.0';

function OnBeforeFolderChange(beforeFolderChangeData) {
    var tab =;
    if (tab.quickfilter.filter == '') return;
    tab.vars.Set(String(tab.path), tab.quickfilter.filter);

function OnAfterFolderChange(afterFolderChangeData) {
    var tab =;
    var tabPath = String(tab.path);
    if (tabPath == 'undefined') return; // this seems to potentially be the case when Layouts or Tabgroups get opened

    if (!tab.vars.Exists(tabPath)) return;

    var cmd = DOpus.Create().Command();
    cmd.RunCommand('Set QUICKFILTER="' + tab.vars.Get(tabPath) + '"');

Save EventSaveQuickFilter.js.txt to

%appdata%\GPSoftware\Directory Opus\Script AddIns

and use this button to turn the add-in on and off:

Prefs SCRIPTDISABLE="EventSaveQuickFilter.js*,toggle"
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
	<function type="normal">
		<instruction>Prefs SCRIPTDISABLE=&quot;EventSaveQuickFilter.js*,toggle&quot;</instruction>

How to use buttons and scripts from this forum