How to copy basic file properties to clipboard?

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

Hi guys, sorry for recalling this old post but this post is really helpful to me. Could you guys help me with this please! I need to copy these properties to clipboard:

  1. Name
  2. Size
  3. Length (for audio and video files)
    Could you please help me write a script? I really appreciate this, thank you!!

Alternatively, you could use ClipCopy:

ClipCopy VALUES=name,size,duration

FWIW you may also have a look at
https://resource.dopus.com/t/how-to-copy-basic-file-properties-to-clipboard/25556/21

SnagIt-23052024 143718

Opus 13 also lets you select and copy data straight out of the file display, for more ad-hoc tasks.

And the Print/Export Folder UI/command can cover most other needs, if Opus already shows the data you want.