Clipboard COPYNAMES FILE REGEXP (\d\dh\d\dm) \1

Greetings Opus Comrades!

I have filenames with date time stamps in them and I often extract the timestamp only with this nifty internal command in a filetype context menu:

Clipboard COPYNAMES FILE REGEXP (\d\dh\d\dm) \1

So far so good.
If I select 2 files, for example

2020-10-10 18h33m129 Maxalt 0.5.jpg
2020-10-10 18h33m128 Maxalt 0.5.jpg

Then both timestamps are copied to the clipboard with a CR ie this appears in the clipboard:


I want to select 2 files and then only copy the bottom timestamp to the clipboard.
I want in the sample above to have only this in the clipboard:

How do I do that?
The reason is after I have copied the timestamp I paste it into a spreadsheet I then add a prefix to both files to show they have been processed.
A bit involved to explain more fully than that I can do if anyone wants.

Back to the problem.
Somehow I need to get rid of all the lines in the clipboard accept the last line.
If I could think up a very fancy regex that filters out all but the last timestamp?
I am not sure of the mechanics of the COPYNAME switch - does that make the command act once on ever selected file?
Not sure hope to tackle with internal commands.

Would it be necessary to use a script?
Any views muchly appreciated....

This script should do it.

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

    var i = tab.selected_files.count;
    if (i == 0) return;
    var cmdLine = 'Clipboard COPYNAMES FILE="' + tab.selected_files(i - 1) + '" REGEXP (\\d\\dh\\d\\dm) \\1';
    // DOpus.Output(cmdLine);

36951.dcf (945 Bytes)

1 Like

@lxp - Very very helpful and fascinating to boot.
I have been meaning to start using Java as recommended by you some time ago.
This is the first time I am doing so.
Your script works but I have discovered there is a problem if there are spaces in the filename.
Script works for these 2 sample files:


Giving the desired output:

But not for these 2 sample files (my actual files have spaces)

2020-10-19 16h07m53 Maxalt 1.0.jpg
2020-10-19 16h07m11 Maxalt 1.0.jpg

Giving the these 4 lines:


I am focused in on exactly how the REGEXP switch operates currently
I wonder if I am understanding things correctly - that is the script is working fine?
I manually created this internal command string:

Clipboard COPYNAMES FILE="C:\Users\slouw\OneDrive\Docs\BMS\Daily\2020-10-19 16h44m53 Maxalt 1.0.jpg" REGEXP (\d\dh\d\dm) \1

Adding in inverted commas to accommodate the spaces in the filename
And I get this result similar to the script output:


Is there a REGEX change I can make?
Or maybe I could/should within the script replace the spaces with underscore?
that might just go around it..

My thanks again....

The internal command can be made to work by having a more complete REGEX string
This works:

Clipboard COPYNAMES FILE="C:\Users\slouw\OneDrive\Docs\BMS\Daily\Test\2020-10-19 16h44m53 Maxalt 1.0.jpg" REGEXP (.*)(\d\dh\d\dm)(.*) \2

Giving the desired output:

Next step then to add the double vertical quotes to the string within the string in the script...

Making this change to the script did not work as expected.
The quotes keyword has been added:
var cmdLine = 'Clipboard COPYNAMES=quotes FILE=' + tab.selected_files(i - 1) + ' REGEXP (.*)(\\d\\dh\\d\\dm)(.*) \\2';

Again I take a step back and run this internal command:
Clipboard COPYNAMES=quotes
The result in the clipboard is the filename of the 2 files I had selected at execution time:

C:\Users\slouw\OneDrive\Docs\BMS\Daily\2020-10-19 16h44m53 Maxalt 1.0.jpg
C:\Users\slouw\OneDrive\Docs\BMS\Daily\2020-10-19 16h07m11 Maxalt 1.0.jpg

I was expecting quotes but there are none.
What am I doing wrong?

You'll probably want quotes around the file path:

var cmdLine = 'Clipboard COPYNAMES=quotes FILE="' + tab.selected_files(i - 1) + '" REGEXP (.*)(\\d\\dh\\d\\dm)(.*) \\2';
//                                             ^                                 ^

That's odd. Works here just fine:


If you plan to expand the script to do more, I'd recommend using properties such as and some JScript string manipulation and setting the clipboard content with DOpus.SetClip() instead of relying on the internal command Clipboard COPYNAMES.

The script will be easier to write and test and to adapt and reuse later.

Maybe share more on the final goal you want to achieve.

@lxp this is wonderful help thank you.
Odd that works for you not me - maybe Opus version or windows bug or something.
No matter I will make it work with quotes with thanks to @Leo.
This is my first JScript and that is long overdue.
Will lookup and make use of Java properties also.
Thank you once again

Final working script.

function OnClick(clickData) {
    var cmd = clickData.func.command;
    var tab = clickData.func.sourcetab;
    cmd.deselect = false;
	DOpus.Output("cmd                :" + cmd);
    var i = tab.selected_files.count;
	DOpus.Output("No files selected  :" + i);
    if (i == 0) return;
//  var cmdLine = 'Clipboard COPYNAMES FILE=' + tab.selected_files(i - 1) + ' REGEXP     (\\d\\dh\\d\\dm)     \\1';
//	var cmdLine = 'Clipboard COPYNAMES FILE=' + tab.selected_files(i - 1) + ' REGEXP (.*)(\\d\\dh\\d\\dm)(.*) \\2';
//	var cmdLine = 'Clipboard COPYNAMES=quotes FILE=' + tab.selected_files(i - 1) + ' REGEXP (.*)(\\d\\dh\\d\\dm)(.*) \\2';
	var cmdLine = 'Clipboard COPYNAMES FILE="' + tab.selected_files(i - 1) + '" REGEXP (.*)(\\d\\dh\\d\\dm)(.*) \\2';
    // DOpus.Output(cmdLine);
	DOpus.Output("cmdLine            :" + cmdLine);

Nice! So this now works with filenames that contain spaces?