Copy Text to clipboard with JSCRIPT

I saw that there is a clipboard internal command, how do I do it in JSCRIPT? I'm creating a button that takes the selected file or folder and creates Markdown for it.

Note that the generated example says "Some essentials (see Scripting Reference in the manual for the rest)" It doesn't provide a URL and I can't find that in the manual.

I'm still hoping there is a function somewhere I can use and a pointer to the script doco, but I managed to get something working well enough for now. Next Ill' try to work out how to associate it to all files/folders context menu (may need more escaping for some files as I'm not that familiar with markdown either):

function OnClick(clickData)
{

	DOpus.Output("GENERATING MARKUP FOR FILE/FOLDER");
	DOpus.Output("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
	
	MarkDownAll = '';
	for (var eSel = new Enumerator(clickData.func.sourcetab.selected); !eSel.atEnd(); eSel.moveNext())
	{
		FileObjName = String( eSel.item().RealPath );
		SafeTitle   = FileObjName.replace(/([\[\]\\])/g, '\\$1');    /* escape '[', ']' & '\' */
		SafeFile    = FileObjName.replace(/\\/g, '/');
		SafeFile    =    SafeFile.replace(/ /g, '+');
		//DOpus.Output("FILE: " + FileObjName);
		//DOpus.Output("TYPE: " + typeof(FileObjName));
		FileUrl     = 'file:///' + SafeFile;
		MarkDown    = '[' + SafeTitle + '](' + FileUrl + ')';
		//MarkDown    = `[${SafeTitle}](${FileUrl})`; //Damb: older version jscript engine...

		if	(MarkDownAll != '')
			MarkDownAll += '\n';
		MarkDownAll += MarkDown;			
	}
	if	(MarkDownAll == '')
		DOpus.Output("NOTHING WAS SELECTED");
	else
	{	
		DOpus.Output(MarkDownAll);
		var cmd = clickData.func.command;
		cmd.RunCommand("Clipboard SET " + MarkDownAll)
	}
}

DOPUS seems to need updating to recent versions of jscript. What version does it used so I can write appropriate code?

You can use DOpus.SetClip() to put data on the clipboard, no need to run a command to do that.

run this in the tools/Opus CLI/Ad-Hoc Script Editor

function GetScriptEngineInfo()
{
    var s= "";
    s += ScriptEngine() + " Version ";
    s += ScriptEngineMajorVersion() + ".";
    s += ScriptEngineMinorVersion() + ".";
    s += ScriptEngineBuildVersion();
    return(s);
}

DOpus.Output(GetScriptEngineInfo());

on windows 11 24H2 you should get JScript Version 11.0.16384 which is a 2024 update to the JScript engine compliant with ECMAScript 2024, otherwise it will be JScript Version 5.something which is a 2009 version.

I think we use this as first line to use the older version

// !JSCRIPTVER=3

As much as I'd like this to be true, it is not. JScript v11 is still roughly Javascript 3. Have you tried to use syntax like let a=1 or const c=2? You'll get an immediate syntax error.

There are few other threads with discussions and requests about newer JScript versions.

// !JSCRIPTVER=3

What this really does is turning on a few backports of a handful functions like .trim() which can be easily implemented via polyfills anyway.

I wonder why... oh, wait... :slight_smile:

JScript engine compliant with [ECMAScript 2024](https://262.ecma-international.org/?utm_source=chatgpt.com#sec-intro), otherwise it will b

Probably what MS meant was, JScript v11 can be run in newer ES environments (thus the minimal changes), but not that JScript supports newer ES syntax.

EDIT: see more findings about javascript/jscript support & !JSCRIPTVER in this thread.

What failed for me was a string in back ticks (which I can't work out how to successfully display here).