Skip to main content
jovannig
Known Participant
February 15, 2020
Question

How to limit the number of keywords in Bridge

  • February 15, 2020
  • 3 replies
  • 3014 views

I use Bridge to edit Title and keywords on my images, then I upload to Adobe Stock.
When I put keywords on my images I usually do it with copy and paste from internet sites.
However usually my images have almost 50 keywords, and I want to limit this number.
Is there a way to limit the number of keywords in Bridge, or, better yet, cut some of them in Bridge with the purpose to have at most 30 of them in every image?
Thanks in advance

 

This topic has been closed for replies.

3 replies

Stephen Marsh
Community Expert
Community Expert
February 25, 2020

Great job as always SuperMerlin!

 

I extended your script with a very simple interactive prompt. There is no error checking or safeguards to ensure that only digits are entered, however that should not be too hard to add if required.

 

 

//Limit Keywords with Prompt.jsx
//How to limit the number of keywords in Bridge
//community.adobe.com/t5/bridge/how-to-limit-the-number-of-keywords-in-bridge/m-p/10945147

#target bridge
if (BridgeTalk.appName == "bridge") {
   keyLimit = MenuElement.create("command", "Limit Keywords", "at the end of tools");
}
keyLimit.onSelect = function () {
   // Interactive Step
   NumberOfKeywords = Window.prompt("Please enter the keyword length limit:", "5");
   try {
      if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
      var sels = app.document.selections;
      for (var a = 0; a < sels.length; a++) {
         var thumb = new Thumbnail(sels[a]);
         var md = thumb.synchronousMetadata;
         var xmp = new XMPMeta(md.serialize());
         if (!xmp.doesPropertyExist(XMPConst.NS_DC, "subject")) continue;
         var keys = [];
         keys = getArrayItems(XMPConst.NS_DC, "subject");

         function getArrayItems(ns, prop) {
            var arrItem = [];
            var items = xmp.countArrayItems(ns, prop);
            for (var i = 1; i <= items; i++) {
               arrItem.push(xmp.getArrayItem(ns, prop, i));
            }
            return arrItem;
         };
         if (keys.length > NumberOfKeywords) {
            xmp.deleteProperty(XMPConst.NS_DC, 'subject');
            for (var k = 0; k < NumberOfKeywords; k++) {
               xmp.appendArrayItem(XMPConst.NS_DC, 'subject', keys[k], 0, XMPConst.PROP_IS_ARRAY);
            }
         }
         var updatedPacket = xmp.serialize(XMPConst.SERIALIZE_USE_COMPACT_FORMAT);
         thumb.metadata = new Metadata(updatedPacket);
      }
   } catch (e) {
      alert(e + "\n" + e.line);
   }
};

 

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

 

Stephen Marsh
Community Expert
Community Expert
February 25, 2020

Entering the keywords in the following order, with a mixutre of digits and alphabetical characters:

 

1, 2, 3, 4, 5, six, 7, eight

 

Has the following display in Bridge CC2019:

 

 

 

 

So as Lumigraphics notes, even within Adobe software, the display order is not consistent.

 

At least the raw data of file info matches what ExifTool states, which is the order of input/entry:

 

 

[IPTC] Keywords : 1, 2, 3, 4, 5, six, 7, eight 
[XMP-dc] Subject : 1, 2, 3, 4, 5, six, 7, eight

 

 

So a solution using ExifTool is readily available, if you are willing to use a CLI based program (there are GUI front ends that can be used to hide most of the command line use of ExifTool if one does need a crutch).

SuperMerlin
Inspiring
February 25, 2020

Yes the display is not the same as the order of the keywords. Here is a javascript that should do the job for selected documents.

#target bridge  
   if( BridgeTalk.appName == "bridge" ) {  
keyLimit = MenuElement.create("command", "Limit Keywords", "at the end of tools");
}
keyLimit.onSelect = function () { 
//adjust to suit
NumberOfKeywords = 25;
try{
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
var sels = app.document.selections;
for(var a =0;a<sels.length;a++){
var thumb =  new  Thumbnail( sels[a] );
var md = thumb.synchronousMetadata;
var xmp =  new XMPMeta(md.serialize());
if(!xmp.doesPropertyExist(XMPConst.NS_DC, "subject")) continue;
var keys =[];
keys = getArrayItems(XMPConst.NS_DC,"subject");
function getArrayItems(ns, prop){
var arrItem=[];
var items = xmp.countArrayItems(ns, prop);
for(var i = 1;i <= items;i++){
arrItem.push(xmp.getArrayItem(ns, prop, i));}
return arrItem;
};
if(keys.length > NumberOfKeywords){
xmp.deleteProperty(XMPConst.NS_DC,'subject');
for(var k =0;k<NumberOfKeywords;k++){
xmp.appendArrayItem(XMPConst.NS_DC, 'subject', keys[k], 0,XMPConst.PROP_IS_ARRAY);
}
}
var updatedPacket = xmp.serialize(XMPConst.SERIALIZE_USE_COMPACT_FORMAT);
thumb.metadata = new Metadata(updatedPacket);
}
}catch(e){alert(e + "\n" + e.line);}
};
Legend
February 16, 2020

Just uncheck the ones you don't want to use.

jovannig
jovannigAuthor
Known Participant
February 16, 2020

Yes, but I was looking for a script / plugin that cuts the number of keywords to a certain number (for example 25 keywords). This procedure must be applied to a folder of images.

Giovanni
Legend
February 20, 2020

How does the script know which 25 to keep?