Skip to main content
Participant
October 29, 2020
Question

Bridge Template Variable Substitution

  • October 29, 2020
  • 2 replies
  • 430 views

When defining a template to set metadata in Bridge, are there any macro-like substitution variables available?  Specifically, I want to set the Title to be the filename of the image file.  Is there a $filename variable or something similar available that I can set as the Title value?

This topic has been closed for replies.

2 replies

Legend
October 30, 2020

#target bridge
if(BridgeTalk.appName == 'bridge'){
try{

//create menus
var ftCmd = MenuElement.create('command', 'Filename to Title', 'at the end of Tools');

var ftContCmd = MenuElement.create('command', 'Filename to Title', 'after Thumbnail/Open', this.menuID);
}
catch(e){
alert(e + ' ' + e.line);
}
}

ftCmd.onSelect = function(){
ftAddFilenameToTitle();
}

ftContCmd.onSelect = function(){
ftAddFilenameToTitle();
}

function ftAddFilenameToTitle(){
try{
var ftThumbs = app.document.selections; //get selected thumbnails
if (!ftThumbs.length) return; //nothing selected
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
for(var a in ftThumbs){ //loop through thumbs
var ftTitle = ftThumbs[a].name; //get filename
//remove filename after last dash character


//to remove filename after dash, uncomment lines
//~ ftTitle = ftTitle.split('-');
//~ if(ftTitle.length > 1){
//~ ftTitle.length--;
//~ }
//~ ftTitle = ftTitle.join('-');


//remove filename after last period character
ftTitle = ftTitle.split('.');
if(ftTitle.length > 1){
ftTitle.length--;
}
ftTitle = ftTitle.join('.');
var ftMeta = ftThumbs[a].synchronousMetadata;
var ftXMP = new XMPMeta(ftMeta.serialize());
ftXMP.deleteProperty(XMPConst.NS_DC, 'title'); //delete old title
ftXMP.appendArrayItem(XMPConst.NS_DC, 'title', ftTitle, 0, XMPConst.ALIAS_TO_ALT_TEXT); //write new title
ftXMP.setQualifier(XMPConst.NS_DC, 'title[1]', 'http://www.w3.org/XML/1998/namespace', 'lang', 'x-default');
var ftUpdatedPacket = ftXMP.serialize(XMPConst.SERIALIZE_OMIT_PACKET_WRAPPER | XMPConst.SERIALIZE_USE_COMPACT_FORMAT);
ftThumbs[a].metadata = new Metadata(ftUpdatedPacket); //write to file
}
}
catch(e){
alert(e + ' ' + e.line);
}
}

Stephen Marsh
Community Expert
Community Expert
October 30, 2020

I am not aware of anything similar to this in a metadata template.

 

There are many stand-alone scripts to place the filename in various metadata fields which can be applied to multiple files. If you search the forum you should get many examples.