Set Quickfilter From Clipboard

This script sets the quickfilter to the clipboard content after replacing various delimiters. It's based on the discussions here and here. The delimiters can be picked by out-commenting the unwanted ones.

// https://resource.dopus.com/t/set-quickfilter-from-clipboard/40606
// 2022-02-20

function OnClick(clickData) {
    if (DOpus.GetClipFormat() != 'text') return;
    var cmd = clickData.func.command;
    cmd.deselect = false;

    var tmp = DOpus.GetClip();
    tmp = DOpus.FSUtil().NewWild().EscapeString(tmp); // Escape characters used in standard pattern matching

    // out-comment as needed
    tmp = tmp.replace(/;/g, '|');
    tmp = tmp.replace(/,/g, '|');
    tmp = tmp.replace(/ /g, '|');
    tmp = tmp.replace(/\r/g, '|'); // return
    tmp = tmp.replace(/\n/g, '|'); // line feed
    tmp = tmp.replace(/\t/g, '|'); // tab

    // here would be the place to insert additional replacements

    tmp = tmp.replace(/\|+/g, '|'); // clean up duplicate |
    tmp = tmp.replace(/^\||\|$/g, ''); // remove leading and trailing |

    var cmdLine = 'Set QUICKFILTER="(' + tmp + ')"';
    // DOpus.Output(cmdLine);
    cmd.RunCommand(cmdLine);
}
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="both" textcol="none">
	<label>Set Quickfilter From Clipboard</label>
	<tip>Turn clipboard content into a quickfilter</tip>
	<icon1>#filterfolder</icon1>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>// https://resource.dopus.com/t/set-quickfilter-from-clipboard/40606</instruction>
		<instruction>// 2022-02-20</instruction>
		<instruction />
		<instruction>function OnClick(clickData) {</instruction>
		<instruction>    if (DOpus.GetClipFormat() != &apos;text&apos;) return;</instruction>
		<instruction>    var cmd = clickData.func.command;</instruction>
		<instruction>    cmd.deselect = false;</instruction>
		<instruction />
		<instruction>    var tmp = DOpus.GetClip();</instruction>
		<instruction>    tmp = DOpus.FSUtil().NewWild().EscapeString(tmp); // Escape characters used in standard pattern matching</instruction>
		<instruction />
		<instruction>    // out-comment as needed</instruction>
		<instruction>    tmp = tmp.replace(/;/g, &apos;|&apos;);</instruction>
		<instruction>    tmp = tmp.replace(/,/g, &apos;|&apos;);</instruction>
		<instruction>    tmp = tmp.replace(/ /g, &apos;|&apos;);</instruction>
		<instruction>    tmp = tmp.replace(/\r/g, &apos;|&apos;); // return</instruction>
		<instruction>    tmp = tmp.replace(/\n/g, &apos;|&apos;); // line feed</instruction>
		<instruction>    tmp = tmp.replace(/\t/g, &apos;|&apos;); // tab</instruction>
		<instruction />
		<instruction>    // here would be the place to insert additional replacements</instruction>
		<instruction />
		<instruction>    tmp = tmp.replace(/\|+/g, &apos;|&apos;); // clean up duplicate |</instruction>
		<instruction>    tmp = tmp.replace(/^\||\|$/g, &apos;&apos;); // remove leading and trailing |</instruction>
		<instruction />
		<instruction>    var cmdLine = &apos;Set QUICKFILTER=&quot;(&apos; + tmp + &apos;)&quot;&apos;;</instruction>
		<instruction>    // DOpus.Output(cmdLine);</instruction>
		<instruction>    cmd.RunCommand(cmdLine);</instruction>
		<instruction>}</instruction>
	</function>
</button>

1 Like