ClipPaste (Paste clipboard to various destinations)

ClipPaste pastes the clipboard to various destinations. The type of paste is determined by parameters.

Parameters

ClipPaste INTONEWCOLLECTION

Creates a dated collection and pastes files from the clipboard into it. Provides an easy way to get results from an Everything window into Opus. Just select and copy in Everything and run the command in Opus or send it to Opus via DOpusRT.

ClipPaste PASTE

Pastes the clipboard as a dated text file into the source, if the clipboard contains text. Uses Opus' standard paste in all other cases.

ClipPaste SNIP

Pastes the clipboard as a dated text file into a Snipfolder /User\PIM (defined in the script, please personalize), if the clipboard contains text. Does nothing in all other cases. Useful if you like to create/keep notes in a central place.

ClipPaste URL

Splits the clipboard contents by lines and whitespaces and pastes it as Internet Shortcuts into the source (one .url file per line), if the clipboard contains text. Does nothing in all other cases. Useful if you manage bookmarks with Opus and want to bring bookmarks from e.g. Chrome into a folder.

NOLOG

Append to suppress logging in the log panel.

How to setup and use

:one: Save CommandClipPaste.js.txt to

%appdata%\GPSoftware\Directory Opus\Script AddIns

:two: Copy this menu to a toolbar or create your own buttons with ClipPaste.

Menu as XML
<?xml version="1.0"?>
<button backcol="none" display="both" dropdown_glyph="yes" label_pos="right" textcol="none" type="menu">
	<label>ClipPaste</label>
	<icon1>#clippaste</icon1>
	<button backcol="none" display="both" label_pos="right" textcol="none">
		<label>Into new collection</label>
		<tip>Creates a dated collection and pastes files from the clipboard into it</tip>
		<icon1>#clippaste</icon1>
		<function type="normal">
			<instruction>ClipPaste INTONEWCOLLECTION</instruction>
		</function>
	</button>
	<button backcol="none" display="both" label_pos="right" textcol="none">
		<label>Paste</label>
		<tip>Pastes the clipboard as a dated textfile into the source</tip>
		<icon1>#clippaste</icon1>
		<function type="normal">
			<instruction>ClipPaste PASTE</instruction>
		</function>
	</button>
	<button backcol="none" display="both" label_pos="right" textcol="none">
		<label>Snip</label>
		<tip>Pastes the clipboard as a dated textfile into Snipfolder</tip>
		<icon1>#clippaste</icon1>
		<function type="normal">
			<instruction>ClipPaste SNIP</instruction>
		</function>
	</button>
	<button backcol="none" display="both" label_pos="right" textcol="none">
		<label>URL</label>
		<icon1>#clippaste</icon1>
		<function type="normal">
			<instruction>ClipPaste URL</instruction>
		</function>
	</button>
</button>

Things you might enjoy reading

How to use buttons and scripts from this forum

The script's inner workings

JScript
function OnInit(initData) {
    initData.name = 'ClipPaste';
    initData.version = '2023-06-14';
    initData.url = 'https://resource.dopus.com/t/clippaste-paste-clipboard-to-various-destinations/44637';
    initData.desc = 'Paste clipboard to various destinations';
    initData.default_enable = true;
    initData.min_version = '12.31';
}

function OnAddCommands(addCmdData) {
    var cmd = addCmdData.AddCommand();
    cmd.name = 'ClipPaste';
    cmd.method = 'OnClipPaste';
    cmd.template = '' +
        'intonewcollection/s,' +
        'paste/s,' +
        'snip/s,' +
        'url/s,' +
        'nolog/s';
    cmd.hide = false;
    cmd.icon = 'script';
}

function OnClipPaste(scriptCmdData) {
    var cmd = scriptCmdData.func.command;
    var tab = scriptCmdData.func.sourcetab;
    var args = scriptCmdData.func.args;
    var fsu = DOpus.FSUtil();

    cmd.deselect = false;

    if (false);
    else if (args.intonewcollection) PasteIntoNewCollection();
    else if (args.paste) PastePaste();
    else if (args.snip) PasteSnip();
    else if (args.url) PasteUrl();

    // ====

    function PasteIntoNewCollection() {
        var newColl = 'coll://Clip-' + DOpus.Create().Date().Format('D#yyyyMMdd-T#HHmmss');
        cmd.RunCommand('CreateFolder NAME="' + newColl + '"');
        cmd.SetSource(newColl);
        cmd.RunCommand('Clipboard PASTE');
        cmd.RunCommand('Go PATH="' + newColl + '" NEWTAB TOFRONT');
    }

    function PastePaste() {
        if (DOpus.GetClipFormat() == 'text') {
            cmd.RunCommand('Clipboard PASTE AS="' + DOpus.Create().Date().Format('D#yyyy-MM-dd T#HH.mm.ss') + '.txt"');
        } else {
            cmd.RunCommand('Clipboard PASTE');
        }
    }

    function PasteSnip() {
        if (DOpus.GetClipFormat() != 'text') return;

        var snipFolder = '/User\\PIM'; // *** Adjust to your preferences
        var snipItem = fsu.GetItem(fsu.Resolve(snipFolder + '\\Snip ' + DOpus.Create().Date().Format('D#yyyy-MM-dd T#HH.mm.ss') + '.txt'));
        cmd.RunCommand('CreateFolder NAME="' + snipItem.path + '"');
        cmd.SetSource(snipItem.path);
        cmd.RunCommand('Clipboard PASTE AS="' + snipItem + '"');
        cmd.RunCommand('Go PATH="' + snipItem + '" OPENCONTAINER NEWTAB=findexisting');

        Log(snipItem);
    }

    function PasteUrl() {
        if (DOpus.GetClipFormat() != 'text') return;

        cmd.ClearFiles();
        var tmp = '';
        var clipLines = DOpus.GetClip().split(/[\r\n\s]/);
        for (var i = 0; i < clipLines.length; i++) {
            var line = clipLines[i];
            if (line.length == 0) continue;
            var tmpFile = fsu.GetTempFile();
            tmpFile.Write('[InternetShortcut]\r\nURL=' + line + '\r\n');
            tmpFile.Close();
            cmd.AddFile(tmpFile);
            tmp += line + '\n';
        }

        cmd.SetDestTab(tab);
        cmd.RunCommand('Copy MOVE AS=InternetShortcut.url WHENEXISTS=rename');

        Log(tmp);
    }

    function Log(str) {
        if (args.nolog) return;
        cmd.RunCommand('Set UTILITY=otherlog');
        // DOpus.ClearOutput();
        DOpus.Output('\n' + str);
    }
}
3 Likes

Dear @lxp
is there a way to rename urls to site names while pasting from clip using ClipPaste URL ?
now it pastes as

InternetShortcut.url
InternetShortcut (1).url
InternetShortcut (2).url
InternetShortcut (3).url
InternetShortcut (4).url
InternetShortcut (5).url

I use this preset to clean up URL files:

Rename to URL