Paste clipboard text to multiple selected text files?

This script adds the clipboard content to all selected files after the original content. Arrange the itemFile.Write lines, if you want a different order. You can also add line breaks to the files with itemFile.Write('\r\n').

// https://resource.dopus.com/t/paste-clipboard-text-to-multiple-selected-text-files/41787

// 2022-07-24

function OnClick(clickData) {
    var cmd = clickData.func.command;
    var tab = clickData.func.sourcetab;
    cmd.deselect = false;

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

    var clipText = DOpus.GetClip();

    for (var e = new Enumerator(tab.selected_files); !e.atEnd(); e.moveNext()) {
        var item = e.item();

        var itemFile = item.Open();
        var origText = itemFile.Read();
        itemFile.Close();

        itemFile = item.Open('w');
        itemFile.Write(origText);
        // enter line
        // itemFile.Write('\r\n'); 
        itemFile.Write(clipText);
        itemFile.Close();
    }
}
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
	<label>AppendClipboard</label>
	<icon1>#clippaste</icon1>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>// https://resource.dopus.com/t/paste-clipboard-text-to-multiple-selected-text-files/41787</instruction>
		<instruction />
		<instruction>// 2022-07-24</instruction>
		<instruction />
		<instruction>function OnClick(clickData) {</instruction>
		<instruction>    var cmd = clickData.func.command;</instruction>
		<instruction>    var tab = clickData.func.sourcetab;</instruction>
		<instruction>    cmd.deselect = false;</instruction>
		<instruction />
		<instruction>    if (DOpus.GetClipFormat() != &apos;text&apos;) return;</instruction>
		<instruction />
		<instruction>    var clipText = DOpus.GetClip();</instruction>
		<instruction />
		<instruction>    for (var e = new Enumerator(tab.selected_files); !e.atEnd(); e.moveNext()) {</instruction>
		<instruction>        var item = e.item();</instruction>
		<instruction />
		<instruction>        var itemFile = item.Open();</instruction>
		<instruction>        var origText = itemFile.Read();</instruction>
		<instruction>        itemFile.Close();</instruction>
		<instruction />
		<instruction>        itemFile = item.Open(&apos;w&apos;);</instruction>
		<instruction>        itemFile.Write(origText);</instruction>
		<instruction>        // enter line</instruction>
		<instruction>        // itemFile.Write(&apos;\r\n&apos;); </instruction>
		<instruction>        itemFile.Write(clipText);</instruction>
		<instruction>        itemFile.Close();</instruction>
		<instruction>    }</instruction>
		<instruction>}</instruction>
	</function>
</button>


4 Likes