Extract portion of filename and add to IPTC Title
Hi - I've found something similar on here from some time ago, but altering the code has stumped me. Our naming convention is follows this pattern : MMC-1234_20200304_123456. We'd like to take everything before the first underscore (MMC-1234) and insert that into the IPTC Title field.
I have a script from an earlier post that does something similar, but I've tried to learn how to update the code without luck. I'll post it here in case it's just a line or two change. TIA!
#target bridge
if(BridgeTalk.appName == "bridge" ) {
addTitle = MenuElement.create("command", "Add Title2", "at the end of Tools");
}
addTitle.onSelect = function () {
var thumbs = app.document.selections;
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
for(var a = 0; a < thumbs.length; a++) {
var selectedFile = new Thumbnail(thumbs[a]);
Title = decodeURI(selectedFile.spec.name).split("_");
if (Title.length < 3) continue;
newTitle = (Title[1] + "_" + Title[2]);
app.synchronousMode = true;
var xmp = new XMPMeta(selectedFile.synchronousMetadata.serialize());
xmp.setLocalizedText( XMPConst.NS_DC, "title", null, "en-US", newTitle);
var newPacket = xmp.serialize(XMPConst.SERIALIZE_USE_COMPACT_FORMAT);
selectedFile.metadata = new Metadata(newPacket);
}
ExternalObject.AdobeXMPScript.unload();
ExternalObject.AdobeXMPScript = undefined;
};
