Skip to main content
Known Participant
May 25, 2021
Answered

how can i split title in ; and copy it in the beginning of description field

  • May 25, 2021
  • 2 replies
  • 259 views

Hello I need help,

i want to copy my title field to the description field, the best on the beginning of the field.

my title field:

car bus van

 

my description field

car; bus; van

 

my try, but how i get all the words with semicolon seperated to the description field.

#target bridge
if( BridgeTalk.appName == "bridge" ) {
FT = MenuElement.create("command", "description", "at the end of Tools");
}
FT.onSelect = function () {
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 FileName = decodeURI(selectedFile.name).slice(0,7);*/
var TitleName = decodeURI(selectedFile.title).match(/z);
var TitleName1 = decodeURI(selectedFile.title).match(/z/L+{/z});
var TitleName2 = decodeURI(selectedFile.title).match(/z/L+/z/L+{/z});
var webshop = ";"
var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
var myXmp = myXmpFile.getXMP();
var Desc=[];
var count = myXmp.countArrayItems(XMPConst.NS_DC, "description");
for(var i = 1;i <= count;i++){
Desc.push(myXmp.getArrayItem(XMPConst.NS_DC, "description", i));
}
Desc=Desc.toString() + " " + webshop + " " + Desc.toString();
myXmp.deleteProperty(XMPConst.NS_DC, "description");
myXmp.appendArrayItem(XMPConst.NS_DC, "description", Desc, 0, XMPConst.ALIAS_TO_ALT_TEXT);
myXmp.setQualifier(XMPConst.NS_DC, "description[1]", "http://www.w3.org/XML/1998/namespace", "lang", "x-default");
if (myXmpFile.canPutXMP(myXmp)) {
myXmpFile.putXMP(myXmp);
myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}
}
}

 

thanks a lot

This topic has been closed for replies.
Correct answer gregreser

I'm not sure if htis meets your needs. It replaces all spaces in title with semicolon+space and adds this to the beginning of the Description. 

 

current title = car bus van

current description = existing description

new description = car; bus; van; existing description

 

#target bridge
if( BridgeTalk.appName == "bridge" ) {
FT = MenuElement.create("command", "description", "at the end of Tools");
}
function loadXMPLib(){
if (ExternalObject.AdobeXMPScript == undefined) {
    ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
	}
}

FT.onSelect = function () {
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 webshop = ";"
var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
var myXmp = myXmpFile.getXMP();

var countTitle = myXmp.countArrayItems(XMPConst.NS_DC, "title");
 var titleString = "";
 if(countTitle > 0){   
    for(var i = 1;i <= countTitle;i++){
        try{
            titleString += myXmp.getArrayItem(XMPConst.NS_DC, "title", i);
            if(i < countTitle) titleString += '; ';
            }
        catch(propFail){
            titleString = "";
            }
        }
    };

var countDesc = myXmp.countArrayItems(XMPConst.NS_DC, "description");
 var descString = "";
 if(countDesc > 0){   
    for(var i = 1;i <= countDesc;i++){
        try{
            descString += myXmp.getArrayItem(XMPConst.NS_DC, "description", i);
            if(i < countDesc) descString += '; ';
            }
        catch(propFail){
            descString = "";
            }
        }
    };
var titleStringSeparated = titleString.replace(/ /g, "; ")
var titleDescCombo = titleStringSeparated+"; "+descString;

myXmp.deleteProperty(XMPConst.NS_DC, "description");
myXmp.appendArrayItem(XMPConst.NS_DC, "description", titleDescCombo, 0, XMPConst.ALIAS_TO_ALT_TEXT);
myXmp.setQualifier(XMPConst.NS_DC, "description[1]", "http://www.w3.org/XML/1998/namespace", "lang", "x-default");
if (myXmpFile.canPutXMP(myXmp)) {
myXmpFile.putXMP(myXmp);
myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}
}
}

 

2 replies

Stephen Marsh
Community Expert
Community Expert
May 28, 2021

@Jörn5F90 – did the reply from @gregreser solve your issue?

 

If it did, please mark the reply as "correct".

 

If it didn't, please let the forum know why and where you are currently at with this issue.

 

gregreser
gregreserCorrect answer
Legend
May 26, 2021

I'm not sure if htis meets your needs. It replaces all spaces in title with semicolon+space and adds this to the beginning of the Description. 

 

current title = car bus van

current description = existing description

new description = car; bus; van; existing description

 

#target bridge
if( BridgeTalk.appName == "bridge" ) {
FT = MenuElement.create("command", "description", "at the end of Tools");
}
function loadXMPLib(){
if (ExternalObject.AdobeXMPScript == undefined) {
    ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
	}
}

FT.onSelect = function () {
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 webshop = ";"
var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
var myXmp = myXmpFile.getXMP();

var countTitle = myXmp.countArrayItems(XMPConst.NS_DC, "title");
 var titleString = "";
 if(countTitle > 0){   
    for(var i = 1;i <= countTitle;i++){
        try{
            titleString += myXmp.getArrayItem(XMPConst.NS_DC, "title", i);
            if(i < countTitle) titleString += '; ';
            }
        catch(propFail){
            titleString = "";
            }
        }
    };

var countDesc = myXmp.countArrayItems(XMPConst.NS_DC, "description");
 var descString = "";
 if(countDesc > 0){   
    for(var i = 1;i <= countDesc;i++){
        try{
            descString += myXmp.getArrayItem(XMPConst.NS_DC, "description", i);
            if(i < countDesc) descString += '; ';
            }
        catch(propFail){
            descString = "";
            }
        }
    };
var titleStringSeparated = titleString.replace(/ /g, "; ")
var titleDescCombo = titleStringSeparated+"; "+descString;

myXmp.deleteProperty(XMPConst.NS_DC, "description");
myXmp.appendArrayItem(XMPConst.NS_DC, "description", titleDescCombo, 0, XMPConst.ALIAS_TO_ALT_TEXT);
myXmp.setQualifier(XMPConst.NS_DC, "description[1]", "http://www.w3.org/XML/1998/namespace", "lang", "x-default");
if (myXmpFile.canPutXMP(myXmp)) {
myXmpFile.putXMP(myXmp);
myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}
}
}