Skip to main content
jovannig
Known Participant
Feb 15, 2020 9:06 AM UTC
Question

How to limit the number of keywords in Bridge

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 is closed to new replies. Start a new post to keep the conversation going.

16 replies

Stephen Marsh
Community Expert
Community Expert
Feb 25, 2020 11:04 AM UTC

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

 

Translate
Stephen Marsh
Community Expert
Community Expert
Feb 25, 2020 1:35 AM UTC

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).

Translate
SuperMerlin
Inspiring
Feb 25, 2020 7:27 AM UTC

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);}
};
Translate
Legend
Feb 16, 2020 2:52 AM UTC

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

Translate
jovannig
jovannigAuthor
Known Participant
Feb 16, 2020 7:08 AM UTC

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.

Translate
Giovanni
Legend
Feb 20, 2020 2:37 PM UTC

How does the script know which 25 to keep?

Translate