How to copy basic file properties to clipboard?

It's not a command so it doesn't have a hotkey. It's just a little feature of the info tip.

Okay, thanks.
Bad luck then.

Paste below into a jscript, script function in new button/shortcut.

function OnClick(data)
{
	data.func.command.deselect = false;
	var clipboard = "";

	var sel = new Enumerator(data.Func.sourcetab.selected_files);
	sel.moveFirst();
	while (sel.atEnd() == false)
	{
		clipboard += "File: " + sel.item().name + "\r\n" +
					 "Path: " + sel.item().path + "\r\n" +
					 "Size: " + sel.item().size.fmt + "\r\n" + 
					 "Creation Date: " + formatDate(sel.item().create) + "\r\n" + 
					 "Modified Date: " + formatDate(sel.item().modify) + "\r\n\r\n";
		sel.moveNext();
	}
	DOpus.SetClip(clipboard);
}
function formatDate(date) {return date.Format("D#MM-dd-yyyy T#HH:mm:ss");}

Script doesn't copy directories.

created a button, script type JScript, pasted above into the box.
when running: no errors "script completed" but regretfully nothing happens.
nothing in clipboard.
what is supposed to happen?

=

Do you have some files selected when you click the button?

Where does it say "script completed"?

  1. Yes
  2. In the logfile (Other logs -> Script Output)

=

The script log would not normally display "Script Completed", at least not for the script above when run from a button or hotkey.

Can you show a screenshot of the button editor so we can see how the script has been set up?

It is rather big screenshot, I am sorry.
The 'green lines' are removed so to reduce the size of the screenshot.
Pasted 'script completed ' right hand top.

=

You don't seem to have pasted the script that @yonder gave you in at all.

AI !
I should take the first plane to Georgia, go and hide in the deepest cave out there.
Else I honestly wouldn't know where to hide...

Actually I clipboard copied the script, then created a toolbar button, selected 'script', then the contents above showed up automatically and at that point, I have to confess and that with a lot of shame, one way or the other I assumed it was copied or so automatically. Felt the code looked different, but didn't check further - was more eager to see the results. tsk, tsk, tsk...

The button works fine now!

@yonder: Many thanks indeed, this is exactly what I was looking for. Perfect.

Deeply sorry for the confusion ...

=

@yonder
I know this is an old thread.

Is there a way to add MD5 and/or SHA1 to the above?

Say, below "Modified Date: " .... a new line:
"MD5": ...

Thanks

The script is reading properties of the Item. The item has many metadata properties, perhaps you can find what you want int there.
Else you might need to get the value another way and add it to the clipboard.
See these

I didn't use DOpus.FSUtil.Hash because the Clipboard COPYNAMES=hash3 command pops up a progress bar so you'll know when the clipbaord is ready to paste when calculating bigger files.

Reminding you that this script only works with files (as I pointed out in my first post)

The way this script was written folders cannot be considered while performing the hash calculations. Otherwise the md5 assigned to a given file would be offset in the list, in other words not correct.

function OnClick(data)
{
	var hash = [], clipboard = "", nl = "\r\n";
	var tclip = DOpus.GetClip();
	var cmd = data.func.command;
	cmd.deselect = false;

	cmd.ClearFiles();
	cmd.AddFiles(data.func.sourcetab.selected_dirs);
	cmd.RunCommand("Select DESELECT FROMSCRIPT")

	var sel_files = data.func.sourcetab.selected_files;
	cmd.ClearFiles();
	cmd.AddFiles(sel_files);
	cmd.RunCommand("Clipboard COPYNAMES=hash3");
	hash = String(DOpus.GetClip("text")).split(nl);

	if (sel_files.count != hash.length)
	{
		DOpus.Output("Unknown error while calculating hashes", true, true);
		cmd.RunCommand("Set UTILITY=otherlog");
		DOpus.SetClip(tclip);
		return;
	}
	
	for (var i=0; i<sel_files.count; i++)
	{
		clipboard += "File: " + sel_files(i).name +nl+
					 "Path: " + sel_files(i).path +nl+
					 "Size: " + sel_files(i).size.fmt +nl+
					 "Creation Date: " + formatDate(sel_files(i).create) +nl+
					 "Modified Date: " + formatDate(sel_files(i).modify) +nl+
					 "MD5: " + hash[i] +nl+nl;
	}
	DOpus.SetClip(clipboard);
}

function formatDate(date) {return date.Format("D#MM-dd-yyyy T#HH:mm:ss");}

The actual deselecting of the folders is not required and was added in for visual reasons. If you want folders to remain selected you can just comment out the three lines below and the folders still will not be accounted for in the hash calculations

//cmd.ClearFiles();
//cmd.AddFiles(data.Func.sourcetab.selected_dirs);
//cmd.RunCommand("Select DESELECT FROMSCRIPT")

Thank you very much!
This indeed is exactly what I have been looking for.

I know, it is meant for single files only. Most of checksum utilities provide the checksums only.
Some may also provide filenames as well, but further details (size, date) are missing.
A tool like HashMyFiles is putting the details side-by-side, without fieldlabels so to say
(Filename, Size, Date.. etc)

Many thanks again!

There's an FSUtil.Hash method if you want to calculate hashes from a script:

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

Thank you Leo.
The script provided is perfect.

As you know I am not familiar with scripts. Regretfully so.
I have really great respect for the script-cracks here, really I do. Don't get me wrong. My interests are elsewhere.

I believe tailoring Opus tends to be more and more a matter of using scripts.
Therefore folks like me depend on others be willing to share their knowledge creating scripts,
or search on Internet for possible other tools, in the event that specific features aren't built in.
I mean no disrespect.

Anyway, as said, the script provided is fine.

Hello again,

Allow me to get back on this.
Q: would it be possible to add
Dimensions
DPI
Bit depth

as well?

SnagIt-26042018%20092532

Thanks!

Set the image and video variable near the top to true or false for desired default settings

image = true;
video = false;

the above settings will pass the dimensions, depth and DPI for images, but not videos to the clipboard.

use key modifiers to override the default variable settings above (example holding shift button before you click the script button will temporarily set both image and video to true).

// key modifier override settings
if (data.func.qualifiers == "shift") { image = true; video = true; }
if (data.func.qualifiers == "ctrl") { image = false; video = false; }

If you run the script through a hotkey the override buttons might conflict with existing hotkeys. For this reason it's better to use the override keys with a toolbar button.

For example if you had this script set to run when you press Ctrl+R the control key will conflict with "ctrl" above, in this case you could set "ctrl" to "alt" key instead to resolve the conflict. Even then there can still be conflicts so keep that in mind if you're using a hotkey to run the script with the key modifiers.

// set true to get dimensions, bit depth and dpi for image and video by default
// image files will get all of above
// video files will only get dimensions
// use key modifiers to override (see below)
var image = true;
var video = false;

function OnClick(data)
{
	var hash = [], clipboard = "", nl = "\r\n";
	var tclip = DOpus.GetClip();
	var cmd = data.func.command;
	cmd.deselect = false;

	// key modifier override settings
	if (data.func.qualifiers == "shift") { image = true; video = true; }
	if (data.func.qualifiers == "ctrl") { image = false; video = false; }

	cmd.ClearFiles();
	cmd.AddFiles(data.func.sourcetab.selected_dirs);
	cmd.RunCommand("Select DESELECT FROMSCRIPT")

	var sel_files = data.func.sourcetab.selected_files;
	cmd.ClearFiles();
	cmd.AddFiles(sel_files);
	cmd.RunCommand("Clipboard COPYNAMES=hash3");
	hash = String(DOpus.GetClip("text")).split(nl);

	if (sel_files.count != hash.length)
	{
		DOpus.Output("Unknown error while calculating hashes", true, true);
		cmd.RunCommand("Set UTILITY=otherlog");
		DOpus.SetClip(tclip);
		return;
	}
	
	for (var i=0; i<sel_files.count; i++)
	{
		var sel_type = sel_files(i).metadata;

		clipboard += "File: " + sel_files(i).name +nl+
					 "Path: " + sel_files(i).path +nl+
					 "Size: " + sel_files(i).size.fmt +nl;

		if ((sel_type == "image" && image) || (sel_type == "video" && video))
		 	clipboard += "Dimensions: " + getMetadata(sel_files(i)) +nl;
					 
		clipboard += "Creation Date: " + formatDate(sel_files(i).create) +nl+
					 "Modified Date: " + formatDate(sel_files(i).modify) +nl+
					 "MD5: " + hash[i] +nl+nl;
	}
	DOpus.SetClip(clipboard);
}

function getMetadata(file)
{
	if (file.metadata == "image")
	{
		var w = file.metadata.image.picwidth;
		var h = file.metadata.image.picheight;
		var depth = file.metadata.image.picdepth;
		var dpix = String(file.metadata.image.picresx).slice(0, -4);
		var dpiy = String(file.metadata.image.picresy).slice(0, -4);
		return w + " x " + h + " x " + depth + " (DPI: " + dpix + " x " + dpiy + ")";
	}
	else if (file.metadata == "video")
	{
		var w = file.metadata.video.picwidth;
		var h = file.metadata.video.picheight;
		return w + " x " + h;
	}
}

function formatDate(date) {return date.Format("D#MM-dd-yyyy T#HH:mm:ss");}

Thank you very much indeed!

That works fine.
Truly appreciated, really.

Folder name and size to the clipboard added...

Items are copied in the order they appear in the lister. If you copy files and folders at once and you want the folders at the top of the clipboard text sort your lister that way.

// set true to get dimensions, bit depth and dpi for image and video by default
// image files will get all of above
// video files will only get dimensions
// use key modifiers to override (see below)
var image = true;
var video = false;

function OnClick(data)
{
	var hash = [], clipboard = "", nl = "\r\n";
	var tclip = DOpus.GetClip();
	var cmd = data.func.command;
	cmd.deselect = false;

	// key modifier override settings
	if (data.func.qualifiers == "shift") { image = true; video = true; }
	if (data.func.qualifiers == "ctrl") { image = false; video = false; }

	var sel_dirs = data.func.sourcetab.selected_dirs;
	if (sel_dirs.count > 0)
	{
		cmd.ClearFiles();
		cmd.AddFiles(sel_dirs);
		cmd.RunCommand("GetSizes");
		if (!cmd.results.result)
			return;
	}

	var sel_items = data.func.sourcetab.selected;
	cmd.ClearFiles();
	cmd.AddFiles(sel_items);
	cmd.RunCommand("Clipboard COPYNAMES=hash3");
	if (!cmd.results.result)
		return;
	
	DOpus.Delay(250);
	hash = String(DOpus.GetClip("text")).split(nl);

	if (sel_items.count != hash.length)
	{
		DOpus.Output("Unknown error while calculating hashes", true, true);
		cmd.RunCommand("Set UTILITY=otherlog");
		DOpus.SetClip(tclip);
		return;
	}

	for (var i=0; i<sel_items.count; i++)
	{
		if (sel_items(i).is_dir)
		{
			// remove .name on the next line if you want full path
			clipboard += "Folder: " + sel_items(i).name +nl+
						 "Size: " + sel_items(i).size.fmt +nl+nl;
		}
		else
		{
			var sel_type = sel_items(i).metadata;

			clipboard += "File: " + sel_items(i).name +nl+
						 "Path: " + sel_items(i).path +nl+
						 "Size: " + sel_items(i).size.fmt +nl;

			if ((sel_type == "image" && image) || (sel_type == "video" && video))
			 	clipboard += "Dimensions: " + getMetadata(sel_items(i), sel_type) +nl;

			clipboard += "Creation Date: " + formatDate(sel_items(i).create) +nl+
						 "Modified Date: " + formatDate(sel_items(i).modify) +nl+
						 "MD5: " + hash[i] +nl+nl;
		}
	}
	DOpus.SetClip(clipboard);
}

function getMetadata(file, type)
{
	if (type == "image")
	{
		var w = file.metadata.image.picwidth;
		var h = file.metadata.image.picheight;
		var depth = file.metadata.image.picdepth;
		var dpix = String(file.metadata.image.picresx).slice(0, -4);
		var dpiy = String(file.metadata.image.picresy).slice(0, -4);
		return w + " x " + h + " x " + depth + " (DPI: " + dpix + " x " + dpiy + ")";
	}
	else if (type == "video")
	{
		var w = file.metadata.video.picwidth;
		var h = file.metadata.video.picheight;
		return w + " x " + h;
	}
}

function formatDate(date) {return date.Format("D#MM-dd-yyyy T#HH:mm:ss");}

1 Like