Skip to main content
Known Participant
May 14, 2021
Answered

Bridge: how can i shorten Metadata field to copy it

  • May 14, 2021
  • 1 reply
  • 1133 views

Hello,

i want to copy a metadata field from on field to the other.

abcdef12345

But i want to copy online 12345?

How can i do this?

Thanks, Jörn

This topic has been closed for replies.
Correct answer gregreser

I should have asked what is not working. The script runs and writes data, so I assume the problem is that the resulting value is not correct. I got the entire filename written to SubjectCode when I tested it.

 

If your filenames always have the same format this will not be hard. 

As an example, if your filename is abcdef20000032.jpg

and you only want the subject code "20000032"

you would use this substr:

var Credit = decodeURI(selectedFile.name).substr(6, 8);

 

If your filenames have a variable number of characters or the file extensions are not always 3 characters, then it will be harder, but not too hard.

 


The other problem is that Iptc4xmpCore:SubjectCode is not a langAlt array, it's a bag array, so it was being written incorrectly.

 

I added a different substr that will work if your filenames are different lengths and are formatted [charactersYouDoNotwant][8 character IPTC SubjectCode].[3 character extension] 

#target bridge
if( BridgeTalk.appName == "bridge" ) {
FT = MenuElement.create("command", "Add FileName to IPTC Suject code", "at the end of Tools");
}
FT.onSelect = function () {
AddFilenameToCredit();
}
function AddFilenameToCredit(){
var thumbs = app.document.selections;
if(!thumbs.length) return;
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
for(var a in thumbs){
var selectedFile = thumbs[a].spec;
var str = decodeURI(selectedFile.name);
// works if filename is formatted [charactersYouDoNotwant][8 character IPTC SubjectCode].[3 character extension]  example: abcdef20000032.jpg
var Credit = str.substring(str.length-12, str.length-4);
// works if filename is always the same length
//var Credit = str.substr(6, 8);

var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
var myXmp = myXmpFile.getXMP();
myXmp.deleteProperty(XMPConst.NS_IPTC_CORE, "Iptc4xmpCore:SubjectCode");
myXmp.appendArrayItem(XMPConst.NS_IPTC_CORE, "Iptc4xmpCore:SubjectCode", Credit, 0, XMPConst.ARRAY_IS_UNORDERED);
if (myXmpFile.canPutXMP(myXmp)) {
myXmpFile.putXMP(myXmp);
myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}
}
}

 

1 reply

Jörn5F90Author
Known Participant
May 14, 2021

not online, only.

Jörn5F90Author
Known Participant
May 15, 2021

My code, but doesn` t work.

 

#target bridge
if( BridgeTalk.appName == "bridge" ) {
FT = MenuElement.create("command", "Add FileName to IPTC Suject code", "at the end of Tools");
}
FT.onSelect = function () {
AddFilenameToCredit();
}
function AddFilenameToCredit(){
var thumbs = app.document.selections;
if(!thumbs.length) return;
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
for(var a in thumbs){
var selectedFile = thumbs[a].spec;
//var Credit = decodeURI(selectedFile.name).substr(length -13, length -4);
var Credit = decodeURI(selectedFile.name).replace(1,2);
var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN,
XMPConst.OPEN_FOR_UPDATE);
var myXmp = myXmpFile.getXMP();
myXmp.deleteProperty(XMPConst.NS_IPTC_CORE, "Iptc4xmpCore:SubjectCode");
myXmp.appendArrayItem(XMPConst.NS_IPTC_CORE, "Iptc4xmpCore:SubjectCode", Credit, 0,
XMPConst.ALIAS_TO_ALT_TEXT);
myXmp.setQualifier(XMPConst.NS_IPTC_CORE, "Iptc4xmpCore:SubjectCode[1]",
"http://www.w3.org/XML/1998/namespace", "lang", "x-default");
if (myXmpFile.canPutXMP(myXmp)) {
myXmpFile.putXMP(myXmp);
myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}
}
}

 

can anyone help

gregreser
Legend
May 16, 2021

The other problem is that Iptc4xmpCore:SubjectCode is not a langAlt array, it's a bag array, so it was being written incorrectly.

 

What is the different betwen this two arrays?


There are three types of arrays in XMP

1. bag is an unordered array. The items order in the list do not matter and an application is not costrained to display them in any particular order. For example, keywords (dc:subject) display order is not enforced.

 

2. seq is an ordered array. The items order in the list is meaningful and applications are expected to display them in the same order as they are written in the XMP. For example, mutliple creators might be listed in order of importance (dc:creator).

 

3. langAlt (language alternative) is an ordered array and has language qualifiers that allow applications to display a language variant. For example, the copyright notice (dc:rights) could be written to XMP in several languages and the application could display the text that matches the user's system language. Typically, only one languge is saved in XMP using the qualifier "x-default" (meaning it is the default value to be displayed), but it is possible to specify other IETF RFC 3066 language qualifiers. Except for custom scripts, Bridge does not save multiple languages, as far as I know, it is usually "x-default"

 

When writing XMP, it is critical to use the proper XMP property type (there are other types besides arrays) in order to create valid, readable metadata. See the XMP Specification  for more info.  Part 1, Data model, Serialization, and Core Properties explains property types and has a list of core properties.