Bridge: how can i shorten Metadata field to copy it
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
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
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);
}
}
}
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.