Writing file name to metadata

That was quick tbone; thanks. Now it's to the DOpus manual to learn how to set up a button. It's about time I learnt such stuff.
Robert

It didn't take long. I've got my button and it works well, putting the existing file name as a tag in the extended properties group. Thanks again.

Oops, I spoke too soon. When I apply the store-in-metadata button to a selection of files the file name of the first file in the list is stored in metadata of every file in the list. To make the button work I'd have to apply it to one file at a time.
Does anyone have an idea why this is and how to get around this?

This was posted by Naki and should do what you want.

@nodeselect 
@sync:dopusrt /acmd SetAttr {filepath} META comment:{file|noext}

While testing, I noticed on .txt files, it does write to the Extended Properties: Comments field


but it does not display in the column.


Using DO12.0.11

I actually don't see why using just {file} would add the name from the first file to comments/tags of other selected files.
Is that how it's meant to work in DO? Is there a proper way around that?

Anyway, the following does not suffer from the unwanted behaviour:
It should be noticeably faster for few or many files too compared to using the external "dopusrt.exe" (needs button of type script, jscript):

function OnClick(data){
	var f = data.func, c = f.command, tab = f.sourcetab, sel = tab.selected;
	for(var i=0;i<sel.count;i++)
		c.RunCommand('SetAttr FILE="'+sel(i).realpath+'" META="tags:+oldname:\''+sel(i).name+'\'');
}

The SetAttr command works on all selected files by default, so the command is parsed one (for the first filename), passed to SetAttr, which runs on everything leaving no files selected for subsequent runs.

If you give the command the name of a specific file to work on (as your script is doing) then it should work.

I tried the above, the @nodeselect / @sync command whilst also using DO12.0.11.
Noticed that existing descriptions are not overwritten, text is added.
Wonder whether overwriting would be possible.

BTW when I restore the same files from a backup, the overwrite warning does not show that the 'new' descriptions in the new files (with ones with updated descriptions)

=

Thanks ktbcrash. My search had missed Naki's contribution. I see that the data written to the Comment field of Extended Properties does in fact show up in the Lister's column (Documents - Comments). See attached screen shot.
One advantage of tbone's solution is that it appends the file's name to the Tag field rather than overwriting existing Comments as your script does. Appending provides a history of file name changes. I may start with a raw file from the camera, rename to TIFF for post processing and rename again to jpg for distribution. This is a nice touch. For this reason I've modified your suggestion a little to include the file's extension in the metadata.
Does anyone know how to change this so that the Comment (or Tag) is appended instead of overwritten?
Thanks in advance
Robert




P.S.
Displaying the Comments field in a column of a Lister displays data only for image files. In my testing it displays data for jpg and TIF but not for ARW (camera raw). Puzzling.
Robert

Thanks for the tip (about Comments)
In the screenshot earlier this thread I got the impression it was in the description.

Am a bit confused.

Did the same on a photo and some files.

got the below (note 2 descriptions)

Comments: rightclick column ->Documents->Comments
Description:

=

Thanks for the tip (about Comments)
In the screenshot earlier this thread I got the impression it was in the description.

Am a bit confused.

Did the same on a photo and some files.

=

Using tbone's script the file name was written to the Tag field. Using kbtcrash's suggestion it was written to the comment field but not when the file is a raw. With raw files no data is written to the comment field.
You're not the only one confused. I'm sure the 'Invalid EXIF text encoding' message is significant.

thanks. I am talking about .jpg files.
regretfully enough I have no idea how to apply the script.

@jon
Thanks for the details regarding SetAttr and the details about how the FILE parameter changes what {file} is resolved to.
Hope to remember that the next time. o)

@opw62
The script snippet is meant to be used in a script button.
Copy and paste the following button definition onto any toolbar while in customize mode and you end up with a working button.

<?xml version="1.0"?>
<button backcol="none" display="label" textcol="none">
	<label>SetMetaTest</label>
	<icon1>#newcommand</icon1>
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>function OnClick(data){</instruction>
		<instruction>	var f = data.func, c = f.command, tab = f.sourcetab, sel = tab.selected;</instruction>
		<instruction>	for(var i=0;i&lt;sel.count;i++)</instruction>
		<instruction>		c.RunCommand(&apos;SetAttr FILE=&quot;&apos;+sel(i).realpath+&apos;&quot; META=&quot;tags:+oldname:\&apos;&apos;+sel(i).name+&apos;\&apos;&apos;);</instruction>
		<instruction>}</instruction>
	</function>
</button>

I'm not getting very far at all so I'd like to summarise my position in the hope someone can help:
The script I'm using is:
@nodeselect
@sync:dopusrt /acmd SetAttr {filepath} META comment:previousname:{file}

This puts the file's name in the User Comment field (see grab) but EXIFtool reports 'Invalid EXIF text encoding for User Comment' (see grab). My DAM software IMatch doesn't find any data in this field. IMatch requires UTF-8 encoding for metadata.
The script is not able to write the file's name to metadata of camera raw files (see grab). I've tested the script with jpg and TIF. It works and presumably will work with other image files.
My questions:

  1. How do I write metadata without causing an invalid encoding error?
  2. How do I write metadata to camera raw files?
  3. How do I append the file's name to the Comment field rather than overwriting the existing comment? I want to have a history of file name changes.
    Thanks in advance for your time,
    Robert





tbone, what I wrote in my last post applies also to the script in your last post of Wed Aug 10, 2016 11:25 am
robert

@tbone
Thank you very much. Noticed changes.
File: Christmas Tree 2015.JPG
after applying the script:
IPTC Core Keywords read: oldname:'Christmas Tree 2015.JPG'
under ExifToolGUI it is listed under XMP

Many thanks again.

=

Hi opw62,

Can you please post what you final solution/code was to get the results in your last screenshot? I would like to do the same via rename tool using JScript but also add the original modified and created date to the description as well. Will see how far I can get... Thanks!

You may wish to use the script from tbone above.
Probably that will work.

=

It does!
8 years later thank you tbone! The fact that I've not come across anything newer suggests that it is still the way to go.