# Set Quickfilter From Clipboard

**URL:** <https://resource.dopus.com/t/set-quickfilter-from-clipboard/40606>\
**Category:** Buttons/Scripts\
**Tags:** jscript\
**Created:** [February 20, 2022, 10:39pm UTC](https://resource.dopus.com/t/set-quickfilter-from-clipboard/40606 "2022-02-20T22:39:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lxp](https://resource.dopus.com/user_avatar/resource.dopus.com/lxp/32/33734_2.png) [@lxp](https://resource.dopus.com/u/lxp)\
**Post date:** [February 20, 2022, 10:39pm UTC](https://resource.dopus.com/t/set-quickfilter-from-clipboard/40606/1 "2022-02-20T22:39:04Z")

</div>

This script sets the quickfilter to the clipboard content after replacing various delimiters. It's based on the discussions [here](https://resource.dopus.com/t/filter-select-multiple-files/36036) and [here](https://resource.dopus.com/t/any-way-to-select-files-containing-text-from-clipboard-without-retyping-in-fayt-and-reactive-lister/40599). The delimiters can be picked by out-commenting the unwanted ones.

```javascript
// 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**
>
> ```plaintext
> <?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>
> 
> ```

* * *

> [@How to use buttons and scripts from this forum](https://resource.dopus.com/t/how-to-use-buttons-and-scripts-from-this-forum/3546):
>
> This post explains how to add buttons to toolbars and menus, and also applies to raw commands for things like standalone hotkeys. For how to use Script Add-Ins, please scroll down to the post below this one. See Also: The manual has more detail in…
