Javascript to insert text from clipboard

Hi,
I'm kind of stuck.
I am creating a button that should create a new file from text.
The text is from a web page via windows clipboard and add a .srt extension.
Why javascript, it should still remove the diacritics and replace the spaces with -.
For renaming it works for me, but create file from windows clipboard via javascript = hitch.

Thanks from the tip/direction.

DOpus.GetClipFormat can tell you if there's text in the clipboard.

DOpus.GetClip can get the text.

More detail: https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Scripting/DOpus.htm

1 Like

Thanks, Leo, for the directions.
I don't speak much English and I thought the DOpus.GetClip command only applied to Dopus not JavaScript, now I'm finding other examples, nothing before.
Have a nice day and thank you again.

1 Like

Your idea sounds interesting. Maybe you want to share your button when it's finished?

I have a button where a new .url file is created and the contents of the clipboards are pasted. Maybe you'll find some code you need in there.

else {
            // Create a FileSystemObject
            var objFSO = new ActiveXObject('Scripting.FileSystemObject');

            // Create a new text file with the filename
            var objFile = objFSO.CreateTextFile(PathName, true);

            // Write the contents of the URL shortcut to the file
            objFile.Write('[InternetShortcut]\r\n');
            objFile.Write('URL=' + ClipboardData + '\r\n');

            // Close the file
            objFile.Close();
        }
2 Likes

Thanks so much for the tip and the directions.
I hastily did it this way, probably not optimal, but it's running now.

function OnClick(clickData) {
var ClipboardData = DOpus.GetClip("text")
//DOpus.Output(ClipboardData)
var objFSO = new ActiveXObject('Scripting.FileSystemObject');
var FileName = clickData.func.SourceTab.Path + '\\' + ClipboardData + '.srt';
DOpus.Output(FileName)
var objFile = objFSO.CreateTextFile(FileName, true);
}

I have removed the accents and spaces elsewhere, as follows

function OnGetNewName(getNewNameData)
{
s_diak="áäčďéěíĺľňóôőöŕšťúůűüýřžÁÄČĎÉĚÍĹĽŇÓÔŐÖŔŠŤÚŮŰÜÝŘŽ ";
bez_diak="aacdeeillnoooorstuuuuyrzAACDEEILLNOOOORSTUUUUYRZ-";
cesta = getNewNameData.item;
nazev = cesta.name_stem;
result = cesta.name_stem + " TEST" + cesta.ext;
text = cesta.name_stem; 
text="";
for(p=0;p<nazev.length;p++)
{
if (s_diak.indexOf(nazev.charAt(p))!=-1)
text+=bez_diak.charAt(s_diak.indexOf(nazev.charAt(p)));
else text+=nazev.charAt(p);
}
	DOpus.Output("Name      = " + cesta.name);
	DOpus.Output("Name Stem = " + cesta.name_stem);
	DOpus.Output("Extension = " + cesta.ext);
	DOpus.Output("Result    = " + result);
	DOpus.Output("---------");
	DOpus.Output("Name      = " + text);
	return result = text+cesta.ext;
}