batch rename using description metadata

Upload Adobe Bridge Scripts, Download Adobe Bridge Scripts, Support for Individual Adobe Bridge Scripts

Moderators: Tom, Kukurykus

claudiu

batch rename using description metadata

Post by claudiu »

Hello guy
Is there any chance to batch rename all my files using the "description" field from the metadata of a jpg image?
In this moment bridge doesn't have the description in this dropdown field only the ones below plus headline, urgency, title that are not visible

claudiu

batch rename using description metadata

Post by claudiu »

nobody?
Paul MR

batch rename using description metadata

Post by Paul MR »

You could try this, it also sets the preserved filename so that you can revert if required...

Code: Select all#target bridge
if( BridgeTalk.appName == "bridge" ) {
RenDesc = new MenuElement("command", "Rename to Description", "at the end of tools");
}
RenDesc.onSelect = function () {
var sels = app.document.selections;
for(var i=0; i < sels.length; i++) {
try{
var thumb = sels;
var selectedFile = thumb.spec;
md = new Thumbnail(selectedFile).synchronousMetadata;
md.namespace = "http://purl.org/dc/elements/1.1/";
Desc = md.description;
if(Desc == '') continue;
Desc = Desc.toString().replace(/[:\/\\*\?\"\<\>\|]/g, "_");
md.namespace = "http://ns.adobe.com/xap/1.0/mm/";
md.PreservedFileName='';
md.PreservedFileName = selectedFile.name;
var ext = thumb.name.match(/\..+$/);
$.sleep(40);
File(selectedFile).rename((Desc+ext));
}catch(e){alert(e + " - " + e.line);}
}
};

claudiu

batch rename using description metadata

Post by claudiu »

you are a genius Paul. Thank you a lot
claudiu

batch rename using description metadata

Post by claudiu »

One more thing. For example through all my files will be also images without descrition in the metadata. could this script rename them with a letter or a number, or a sequence number? now i get this error and i can't close bridge only with end process


Uploaded with ImageShack.us
Paul MR

batch rename using description metadata

Post by Paul MR »

The error is due to the nename being very fast and the metadata has not been updated.
I.E. the file name has been changed before the metadata field has been written to, that is why the $.sleep();
This time I have done two loops one to set the preserved name and one to do the rename, even doing it this way a sleep is required to allow time to update the metadata. If you still get an error increase the sleep time.

Code: Select all#target bridge
if( BridgeTalk.appName == "bridge" ) {
RenDesc = new MenuElement("command", "Rename to Description", "at the end of tools");
}
RenDesc.onSelect = function () {
var sels = app.document.selections;
try{
for(var i=0; i < sels.length; i++) {
var thumb = sels;
var selectedFile = thumb.spec;
md = new Thumbnail(selectedFile).synchronousMetadata;
md.namespace = "http://ns.adobe.com/xap/1.0/mm/";
md.PreservedFileName='';
md.PreservedFileName = selectedFile.name;
}
$.sleep(400);//allow time to update metadata fields
for(var z=0; z < sels.length; z++) {
var thumb = sels[z];
var selectedFile = thumb.spec;
md = new Thumbnail(selectedFile).synchronousMetadata;
md.namespace = "http://purl.org/dc/elements/1.1/";
Desc = md.description;
if(Desc == ''){
    //change to suit your needs
    Desc = "desc-" + zeroPad((z+1),4);
    }else{
Desc = Desc.toString().replace(/[:\/\\*\?\"\<\>\|]/g, "_");
}
var ext = thumb.name.match(/\..+$/);
File(selectedFile).rename((Desc+ext));
}
}catch(e){alert(e + " - " + e.line);}
function zeroPad(n, s) {
   n = n.toString();
   while (n.length < s)  n = '0' + n;
   return n;
};
};