Skip to main content
Participating Frequently
April 18, 2023
Answered

Copy Filename to Keyword

  • April 18, 2023
  • 1 reply
  • 1475 views

Hi all,

 

I am looking for a script to copy filename to keyword in Bridge. So far I have found this which runs well for title (http://kasyan.ho.ua/bridge/add_filename_to_description-title.html) but I really need the copy to be in the keyword field. Could it be possible to edit this script to suit my needs?

 

I've not got much experience with Javascript so any help would be much appreciated. 

 

macOS 12.4, Bridge 13.0.3

 

Thanks 

Ollie

 

This topic has been closed for replies.
Correct answer Stephen Marsh

A couple of scripts from my archive, not tested in Bridge 2023...

 

// https://forums.adobe.com/thread/656144
// https://forums.adobe.com/message/9744916
// https://forums.adobe.com/message/9745231
#target bridge
addNametoMeta = {};
addNametoMeta.execute = function(){
  var sels = app.document.selections;
  for (var i = 0; i < sels.length; i++){
var md = sels[i].synchronousMetadata;
    md.namespace = "http://ns.adobe.com/photoshop/1.0/";
    var Name = decodeURI(sels[i].name).replace(/\.[^\.]+$|_/g, ' '); //remove extension | globally remove underscores 
    md.Keywords = md.Keywords + ";" + Name;
  }
}
if (BridgeTalk.appName == "bridge"){
var menu = MenuElement.create( "command", "Filename to Keywords - Removing Underscore", "at the end of Tools");
  menu.onSelect = addNametoMeta.execute;
}

 

 

// https://forums.adobe.com/thread/656144
#target bridge   
addNametoMeta = {};   
addNametoMeta.execute = function(){   
  var sels = app.document.selections;   
  for (var i = 0; i < sels.length; i++){   
var md = sels[i].synchronousMetadata;   
    md.namespace = "http://ns.adobe.com/photoshop/1.0/";   
    var Name = decodeURI(sels[i].name).replace(/\.[^\.]+$/, '');  
    md.Keywords = md.Keywords + ";" + Name;   
  }   
}   
if (BridgeTalk.appName == "bridge"){   
var menu = MenuElement.create( "command", "Save Filename in Keywords", "at the end of Tools");   
  menu.onSelect = addNametoMeta.execute;   
}  

 

The following does work in Bridge 2023:

// https://forums.adobe.com/thread/656144
#target bridge
addNametoMeta = {};
addNametoMeta.execute = function () {
  var sels = app.document.selections;
  for (var i = 0; i < sels.length; i++) {
    var md = sels[i].synchronousMetadata;
    md.namespace = "http://ns.adobe.com/photoshop/1.0/";
    var Name = decodeURI(sels[i].name).replace(/\.[^\.]+$/, '');
    md.Keywords = md.Keywords + ";" + Name;
  }
}
if (BridgeTalk.appName == "bridge") {
  var menu = MenuElement.create("command", "Filename to Keywords", "at the end of Tools");
  menu.onSelect = addNametoMeta.execute;
}  

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

 

1 reply

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
April 18, 2023

A couple of scripts from my archive, not tested in Bridge 2023...

 

// https://forums.adobe.com/thread/656144
// https://forums.adobe.com/message/9744916
// https://forums.adobe.com/message/9745231
#target bridge
addNametoMeta = {};
addNametoMeta.execute = function(){
  var sels = app.document.selections;
  for (var i = 0; i < sels.length; i++){
var md = sels[i].synchronousMetadata;
    md.namespace = "http://ns.adobe.com/photoshop/1.0/";
    var Name = decodeURI(sels[i].name).replace(/\.[^\.]+$|_/g, ' '); //remove extension | globally remove underscores 
    md.Keywords = md.Keywords + ";" + Name;
  }
}
if (BridgeTalk.appName == "bridge"){
var menu = MenuElement.create( "command", "Filename to Keywords - Removing Underscore", "at the end of Tools");
  menu.onSelect = addNametoMeta.execute;
}

 

 

// https://forums.adobe.com/thread/656144
#target bridge   
addNametoMeta = {};   
addNametoMeta.execute = function(){   
  var sels = app.document.selections;   
  for (var i = 0; i < sels.length; i++){   
var md = sels[i].synchronousMetadata;   
    md.namespace = "http://ns.adobe.com/photoshop/1.0/";   
    var Name = decodeURI(sels[i].name).replace(/\.[^\.]+$/, '');  
    md.Keywords = md.Keywords + ";" + Name;   
  }   
}   
if (BridgeTalk.appName == "bridge"){   
var menu = MenuElement.create( "command", "Save Filename in Keywords", "at the end of Tools");   
  menu.onSelect = addNametoMeta.execute;   
}  

 

The following does work in Bridge 2023:

// https://forums.adobe.com/thread/656144
#target bridge
addNametoMeta = {};
addNametoMeta.execute = function () {
  var sels = app.document.selections;
  for (var i = 0; i < sels.length; i++) {
    var md = sels[i].synchronousMetadata;
    md.namespace = "http://ns.adobe.com/photoshop/1.0/";
    var Name = decodeURI(sels[i].name).replace(/\.[^\.]+$/, '');
    md.Keywords = md.Keywords + ";" + Name;
  }
}
if (BridgeTalk.appName == "bridge") {
  var menu = MenuElement.create("command", "Filename to Keywords", "at the end of Tools");
  menu.onSelect = addNametoMeta.execute;
}  

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

 

Stephen Marsh
Community Expert
Community Expert
April 18, 2023

This one sets the filename in the preserved filename metadata (the same field used by Batch Rename):

 

// https://forums.adobe.com/thread/656144
// https://forums.adobe.com/message/9498691
#target bridge
addNametoMeta = {};
addNametoMeta.execute = function(){
  var sels = app.document.selections;
  for (var i = 0; i < sels.length; i++){
var md = sels[i].synchronousMetadata;
    md.namespace = "http://ns.adobe.com/xap/1.0/mm/";
    var Name = decodeURI(sels[i].name).replace(/\.[^\.]+$/, '');
    md.PreservedFileName = md.PreservedFileName + Name;
  }
}
if (BridgeTalk.appName == "bridge"){
var menu = MenuElement.create( "command", "Save Filename in PreservedFileName metadata", "at the end of Tools");
  menu.onSelect = addNametoMeta.execute;
}
Participating Frequently
April 18, 2023

I appreciate your help, I've now got it working! My current filenames are in the following structure

 

1999.326.6-O.tif

1998.500.5-R.tif

 

Do you know if it would be possible to run the same script but to remove everything after and including the hyphon (-), so in this instance the keywords would then simply read 1998.500.5.tif and 1998.500.5.tif?

 

Really appreciate your help with this!