Copy link to clipboard
Copied
Hi,
I have the following code. It edits the metadata of a file and it works as needed, apart from the fact you have to be in the folder of images in order to edit the metadata of those images. What do I need to change in order for me to open up just the parent directory and for the script to go through all the child pages one by one, executing the script?
#target bridge
if( BridgeTalk.appName == "bridge" ) {
var vfRename = new MenuElement( "command", "VF Rename", "at the end of Tools" , "vfRename01" );
}
vfRename.onSelect = function () {
app.document.deselectAll();
var thumbs = app.document.getSelection("jpg");
for(var a in thumbs){
var f =thumbs.spec;
var parts = decodeURI(f.name).replace(/- \d+.jpg$/i,'').split('&&&');
setMetadata( File(f), parts )
}
function setMetadata( file, parts ){
var Title = parts[0].toString() + " at " + parts[1].toString() + " by " + parts[2].toString();
var Desc = parts[0].toString() + " at " + parts[1].toString() + " by " + parts[2].toString();
var Author = parts[2].toString();
if ( !ExternalObject.AdobeXMPScript ) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
var xmpf = new XMPFile( File(file).fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE );
var xmp = xmpf.getXMP();
xmp.deleteProperty(XMPConst.NS_DC, "title");
xmp.appendArrayItem(XMPConst.NS_DC, "title", Title, 0, XMPConst.ALIAS_TO_ALT_TEXT);
xmp.setQualifier(XMPConst.NS_DC, "title[1]", "http://www.w3.org/XML/1998/namespace", "lang", "x-default");
xmp.deleteProperty(XMPConst.NS_DC, "description");
xmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default", Desc );
xmp.deleteProperty(XMPConst.NS_DC, "creator");
xmp.appendArrayItem(XMPConst.NS_DC, "creator", Author, 0, XMPConst.ARRAY_IS_ORDERED);
for(var s in parts){
xmp.appendArrayItem(XMPConst.NS_DC, "subject", parts
, 0,XMPConst.PROP_IS_ARRAY);}
if (xmpf.canPutXMP( xmp )) {
xmpf.putXMP( xmp );
}
xmpf.closeFile( XMPConst.CLOSE_UPDATE_SAFELY );
}
}
if( BridgeTalk.appName == "bridge" ) {
var vfRename = new MenuElement( "command", "VF Rename", "at the end of Tools" , "vfRename01" );
}
vfRename.onSelect = function () {
var folders =[];
var topLevel = Folder(app.document.presentationPath);
folders = FindAllFolders(topLevel, folders);
folders.unshift(topLevel);
for(var f in folders){
alert(folders
var thumbs = folders
for(var a in thumbs){
var f =thumbs;
var parts = decodeURI(f.name).replace(/- \d+.
...Copy link to clipboard
Copied
Untested but should be near.
#target bridge
if( BridgeTalk.appName == "bridge" ) {
var vfRename = new MenuElement( "command", "VF Rename", "at the end of Tools" , "vfRename01" );
}
vfRename.onSelect = function () {
var folders =[];
var topLevel = Folder(app.document.presentationPath);
folders = FindAllFolders(topLevel, folders);
folders.unshift(topLevel);
for(var f in folders){
app.document.thumbnail = folders
; app.document.deselectAll();
var thumbs = app.document.getSelection("jpg");
for(var a in thumbs){
var f =thumbs.spec;
var parts = decodeURI(f.name).replace(/- \d+.jpg$/i,'').split('&&&');
setMetadata( File(f), parts )
}
};
function setMetadata( file, parts ){
var Title = parts[0].toString() + " at " + parts[1].toString() + " by " + parts[2].toString();
var Desc = parts[0].toString() + " at " + parts[1].toString() + " by " + parts[2].toString();
var Author = parts[2].toString();
if ( !ExternalObject.AdobeXMPScript ) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
var xmpf = new XMPFile( File(file).fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE );
var xmp = xmpf.getXMP();
xmp.deleteProperty(XMPConst.NS_DC, "title");
xmp.appendArrayItem(XMPConst.NS_DC, "title", Title, 0, XMPConst.ALIAS_TO_ALT_TEXT);
xmp.setQualifier(XMPConst.NS_DC, "title[1]", "http://www.w3.org/XML/1998/namespace", "lang", "x-default");
xmp.deleteProperty(XMPConst.NS_DC, "description");
xmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default", Desc );
xmp.deleteProperty(XMPConst.NS_DC, "creator");
xmp.appendArrayItem(XMPConst.NS_DC, "creator", Author, 0, XMPConst.ARRAY_IS_ORDERED);
for(var s in parts){
xmp.appendArrayItem(XMPConst.NS_DC, "subject", parts
, 0,XMPConst.PROP_IS_ARRAY);}
if (xmpf.canPutXMP( xmp )) {
xmpf.putXMP( xmp );
}
xmpf.closeFile( XMPConst.CLOSE_UPDATE_SAFELY );
};
function FindAllFolders( srcFolderStr, destArray) {
var fileFolderArray = Folder( srcFolderStr ).getFiles();
for ( var i = 0; i < fileFolderArray.length; i++ ) {
var fileFoldObj = fileFolderArray;
if ( fileFoldObj instanceof File ) {
} else {
destArray.push( Folder(fileFoldObj) );
FindAllFolders( fileFoldObj.toString(), destArray );
}
}
return destArray;
};
};
Copy link to clipboard
Copied
Afraid not - it seems to be looping through but changes aren't made to all photos. It then crashes 90% of the time before it gets to the last folder
Copy link to clipboard
Copied
Again untested, but a different approach.
#target bridge
if( BridgeTalk.appName == "bridge" ) {
var vfRename = new MenuElement( "command", "VF Rename", "at the end of Tools" , "vfRename01" );
}
vfRename.onSelect = function () {
var folders =[];
var topLevel = Folder(app.document.presentationPath);
folders = FindAllFolders(topLevel, folders);
folders.unshift(topLevel);
for(var f in folders){
var thumbs = folders
.getFiles("jpg"); for(var a in thumbs){
var f =thumbs;
var parts = decodeURI(f.name).replace(/- \d+.jpg$/i,'').split('&&&');
setMetadata( File(f), parts )
}
};
function setMetadata( file, parts ){
var Title = parts[0].toString() + " at " + parts[1].toString() + " by " + parts[2].toString();
var Desc = parts[0].toString() + " at " + parts[1].toString() + " by " + parts[2].toString();
var Author = parts[2].toString();
if ( !ExternalObject.AdobeXMPScript ) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
var xmpf = new XMPFile( File(file).fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE );
var xmp = xmpf.getXMP();
xmp.deleteProperty(XMPConst.NS_DC, "title");
xmp.appendArrayItem(XMPConst.NS_DC, "title", Title, 0, XMPConst.ALIAS_TO_ALT_TEXT);
xmp.setQualifier(XMPConst.NS_DC, "title[1]", "http://www.w3.org/XML/1998/namespace", "lang", "x-default");
xmp.deleteProperty(XMPConst.NS_DC, "description");
xmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default", Desc );
xmp.deleteProperty(XMPConst.NS_DC, "creator");
xmp.appendArrayItem(XMPConst.NS_DC, "creator", Author, 0, XMPConst.ARRAY_IS_ORDERED);
for(var s in parts){
xmp.appendArrayItem(XMPConst.NS_DC, "subject", parts
, 0,XMPConst.PROP_IS_ARRAY);}
if (xmpf.canPutXMP( xmp )) {
xmpf.putXMP( xmp );
}
xmpf.closeFile( XMPConst.CLOSE_UPDATE_SAFELY );
};
function FindAllFolders( srcFolderStr, destArray) {
var fileFolderArray = Folder( srcFolderStr ).getFiles();
for ( var i = 0; i < fileFolderArray.length; i++ ) {
var fileFoldObj = fileFolderArray;
if ( fileFoldObj instanceof File ) {
} else {
destArray.push( Folder(fileFoldObj) );
FindAllFolders( fileFoldObj.toString(), destArray );
}
}
return destArray;
};
};
Copy link to clipboard
Copied
Sorry no
I am in the main/parent folder and I can see all the child folders. I run this but nothing gets updated. Should I see it go through the folders?
Copy link to clipboard
Copied
No, everything is done via the top folder. It gets a list of all sub folders, then a list of all jpgs in each folder and process them.
Copy link to clipboard
Copied
No, still no luck.
In the left navigation I have the very top level folder selected called DAM. In my Content window I have all the subfolders. I run it, but nothing is changed.
Really not sure what is going on
Copy link to clipboard
Copied
if( BridgeTalk.appName == "bridge" ) {
var vfRename = new MenuElement( "command", "VF Rename", "at the end of Tools" , "vfRename01" );
}
vfRename.onSelect = function () {
var folders =[];
var topLevel = Folder(app.document.presentationPath);
folders = FindAllFolders(topLevel, folders);
folders.unshift(topLevel);
for(var f in folders){
alert(folders
var thumbs = folders
for(var a in thumbs){
var f =thumbs;
var parts = decodeURI(f.name).replace(/- \d+.jpg$/i,'').split('&&&');
setMetadata( File(f), parts )
}
};
function setMetadata( file, parts ){
var Title = parts[0].toString() + " at " + parts[1].toString() + " by " + parts[2].toString();
var Desc = parts[0].toString() + " at " + parts[1].toString() + " by " + parts[2].toString();
var Author = parts[0].toString() + " || " + parts[1].toString();
var Headline = parts[1].toString();
if ( !ExternalObject.AdobeXMPScript ) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
var xmpf = new XMPFile( File(file).fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE );
var xmp = xmpf.getXMP();
xmp.deleteProperty(XMPConst.NS_DC, "title");
xmp.appendArrayItem(XMPConst.NS_DC, "title", Title, 0, XMPConst.ALIAS_TO_ALT_TEXT);
xmp.setQualifier(XMPConst.NS_DC, "title[1]", "http://www.w3.org/XML/1998/namespace", "lang", "x-default");
xmp.deleteProperty(XMPConst.NS_DC, "description");
xmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default", Desc );
xmp.deleteProperty(XMPConst.NS_DC, "creator");
xmp.appendArrayItem(XMPConst.NS_DC, "creator", Author, 0, XMPConst.ARRAY_IS_ORDERED);
for(var s in parts){
xmp.appendArrayItem(XMPConst.NS_DC, "subject", parts, 0,XMPConst.PROP_IS_ARRAY);
}
if (xmpf.canPutXMP( xmp )) {
xmpf.putXMP( xmp );
}
xmpf.closeFile( XMPConst.CLOSE_UPDATE_SAFELY );
};
function FindAllFolders( srcFolderStr, destArray) {
var fileFolderArray = Folder( srcFolderStr ).getFiles();
for ( var i = 0; i < fileFolderArray.length; i++ ) {
var fileFoldObj = fileFolderArray;
if ( fileFoldObj instanceof File ) {
} else {
destArray.push( Folder(fileFoldObj) );
FindAllFolders( fileFoldObj.toString(), destArray );
}
}
return destArray;
};
};