batch rename using description metadata

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

Moderators: xbytor, DavideBarranca, Paul MR

claudiu

batch rename using description metadata

Postby claudiu » Thu Apr 11, 2013 6:46 am

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

Image



claudiu

batch rename using description metadata

Postby claudiu » Fri Apr 12, 2013 5:42 am

nobody?

Paul MR

batch rename using description metadata

Postby Paul MR » Fri Apr 12, 2013 10:23 am

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[i];
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

Postby claudiu » Tue Apr 16, 2013 8:22 am

you are a genius Paul. Thank you a lot

claudiu

batch rename using description metadata

Postby claudiu » Tue Apr 16, 2013 8:31 am

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
Image

Uploaded with ImageShack.us

Paul MR

batch rename using description metadata

Postby Paul MR » Tue Apr 16, 2013 5:59 pm

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[i];
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;
};
};




Return to “Adobe Bridge Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest