Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
#target bridge
if( BridgeTalk.appName == "bridge" ) {
addInfo = new MenuElement("command", "Update Entry Details", "at the end of Thumbnail");
}
addInfo .onSelect = function () {
main();
}
function main(){
var csv = File.openDialog("Please select CSV file.","CSV File:*.csv");
if(csv != null){
loadXMPScript();
csv.open("r");
while(!csv.eof){
strInputLine = csv.readln();
if (strInputLine.length > 3) {
strInputLine = strInputLine.replace(/\\/g,'/');
inputArray = strInputLine.split(",");
var csvFile = new File(inputArray[0]);
var title = inputArray[1];
var author = inputArray[2];
if(!csvFile.exists) {
alert(csvFile + " Does not exist"); //////////Check if file exists
return;
}
if(csvFile.exists){
var file = new Thumbnail(csvFile);
try{
var xmpFile = new XMPFile(file.path, XMPConst.UNKNOWN,XMPConst.OPEN_FOR_UPDATE);
}catch(e){
alert("Problem opening xmp for update:-\r" + file.path +"\r" +e.message);
return;
}
try{
var xmp = xmpFile.getXMP();
}catch(e){
alert("Problem opening xmp data:-\r" + e.message);
return;
}
xmp.deleteProperty(XMPConst.NS_DC, "creator");
xmp.deleteProperty(XMPConst.NS_DC, "title");
try{
xmp.appendArrayItem(XMPConst.NS_DC, "creator", author, 0,XMPConst.ARRAY_IS_ORDERED);
xmp.appendArrayItem(XMPConst.NS_DC, "title", title, 0,XMPConst.ARRAY_IS_ORDERED);
}catch(e){
alert("Problem writing xmp data:-\r" + e.message);
return;
}
if (xmpFile.canPutXMP(xmp)) {
xmpFile.putXMP(xmp);
}else{
alert("Can not write new metadata to " + csvFile.spec);
}
xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}
}
}
}
}
unloadXMPScript();
function loadXMPScript()
{
var results = new XMPLibMsg("XMPScript Library already loaded", 0, false);
if (!ExternalObject.AdobeXMPScript)
{
try
{
ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
results.message = "XMPScript Library loaded";
}
catch (e)
{
results.message = "ERROR Loading AdobeXMPScript: " + e;
results.line = e.line;
results.error = true;
}
}
return results;
}
function unloadXMPScript()
{
var results = new XMPLibMsg("XMPScript Library not loaded", 0, false);
if( ExternalObject.AdobeXMPScript )
{
try
{
ExternalObject.AdobeXMPScript.unload();
ExternalObject.AdobeXMPScript = undefined;
results.message = "XMPScript Library successfully unloaded";
}
catch (e)
{
results.message = "ERROR unloading AdobeXMPScript: " + e;
results.line = e.line;
results.error = true;
}
}
return results;
}
function XMPLibMsg (inMessage, inLine, inError)
{
this.message = inMessage;
this.line = inLine;
this.error = inError;
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
#target bridge
if( BridgeTalk.appName == "bridge" ) {
addInfo = new MenuElement("command", "Update Entry Details", "at the end of Thumbnail");
}
addInfo .onSelect = function () {
main();
}
function main(){
var csv = File.openDialog("Please select CSV file.","CSV File:*.csv");
if(csv != null){
loadXMPScript();
csv.open("r");
while(!csv.eof){
strInputLine = csv.readln();
if (strInputLine.length > 3) {
strInputLine = strInputLine.replace(/\\/g,'/');
inputArray = strInputLine.split(",");
var csvFile = new File(inputArray[0]);
var title = inputArray[1];
var author = inputArray[2];
if(!csvFile.exists) {
alert(csvFile + " Does not exist"); //////////Check if file exists
return;
}
if(csvFile.exists){
var file = new Thumbnail(csvFile);
try{
var xmpFile = new XMPFile(file.path, XMPConst.UNKNOWN,XMPConst.OPEN_FOR_UPDATE);
}catch(e){
alert("Problem opening xmp for update:-\r" + file.path +"\r" +e.message);
return;
}
try{
var xmp = xmpFile.getXMP();
}catch(e){
alert("Problem opening xmp data:-\r" + e.message);
return;
}
xmp.deleteProperty(XMPConst.NS_DC, "creator");
xmp.deleteProperty(XMPConst.NS_DC, "title");
try{
xmp.appendArrayItem(XMPConst.NS_DC, "creator", author, 0,XMPConst.ARRAY_IS_ORDERED);
xmp.appendArrayItem(XMPConst.NS_DC, "title", title, 0,XMPConst.ARRAY_IS_ORDERED);
}catch(e){
alert("Problem writing xmp data:-\r" + e.message);
return;
}
if (xmpFile.canPutXMP(xmp)) {
xmpFile.putXMP(xmp);
}else{
alert("Can not write new metadata to " + csvFile.spec);
}
xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}
}
}
}
}
unloadXMPScript();
function loadXMPScript()
{
var results = new XMPLibMsg("XMPScript Library already loaded", 0, false);
if (!ExternalObject.AdobeXMPScript)
{
try
{
ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
results.message = "XMPScript Library loaded";
}
catch (e)
{
alert("Could not load AdobeXMPScript \r" + e.message);
results.message = "ERROR Loading AdobeXMPScript: " + e;
results.line = e.line;
results.error = true;
}
}
return results;
}
function unloadXMPScript()
{
var results = new XMPLibMsg("XMPScript Library not loaded", 0, false);
if( ExternalObject.AdobeXMPScript )
{
try
{
ExternalObject.AdobeXMPScript.unload();
ExternalObject.AdobeXMPScript = undefined;
results.message = "XMPScript Library successfully unloaded";
}
catch (e)
{
results.message = "ERROR unloading AdobeXMPScript: " + e;
results.line = e.line;
results.error = true;
}
}
return results;
}
function XMPLibMsg (inMessage, inLine, inError)
{
this.message = inMessage;
this.line = inLine;
this.error = inError;
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
#target bridge
if( BridgeTalk.appName == "bridge" ) {
addInfo = new MenuElement("command", "Update Entry Details", "at the end of Thumbnail");
}
addInfo .onSelect = function () {
main();
}
function main(){
var csv = File.openDialog("Please select CSV file.","CSV File:*.csv");
if(csv != null){
csv.open("r");
while(!csv.eof){
strInputLine = csv.readln();
if (strInputLine.length > 3) { // Make sure it isn't a blank line
strInputLine = strInputLine.replace(/\\/g,'/'); //Change backslash to forward slash.
inputArray = strInputLine.split(",");
var csvFile = new File(inputArray[0]);
var title = inputArray[1];
var author = inputArray[2];
if(csvFile.exists){ //Check if file exists
item = new Thumbnail(csvFile);
md =item.synchronousMetadata;
var result =addTitleAuthor(md,inputArray[1],inputArray[2]);
}
}
}
}
}
function addTitleAuthor(metadata, Title, Author)
{
var strTmpl = "TempTmpl";
var strUser = Folder.userData.absoluteURI;
var filTmpl = new File(strUser + "/Adobe/XMP/Metadata Templates/" + strTmpl + ".xmp");
var fResult = false;
try
{ if (filTmpl.exists)
filTmpl.remove();
fResult = filTmpl.open("w");
if (fResult)
// CS3
{
//CS3
//filTmpl.writeln("<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"Adobe XMP Core 4.1-c037 46.282696, Mon Apr 02 2007 18:36:42 \">");
//CS2
filTmpl.writeln("<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"3.1.2-113\">");
filTmpl.writeln("<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">");
filTmpl.writeln("<rdf:Description rdf:about=\"\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">");
filTmpl.writeln("<dc:title>");
filTmpl.writeln("<rdf:Alt>");
filTmpl.writeln("<rdf:li xml:lang=\"x-default\">"+Title+"</rdf:li>");
filTmpl.writeln("</rdf:Alt>");
filTmpl.writeln("</dc:title>");
filTmpl.writeln("<dc:creator>");
filTmpl.writeln("<rdf:Seq>");
filTmpl.writeln("<rdf:li>" + Author + "</rdf:li>");
filTmpl.writeln("</rdf:Seq>");
filTmpl.writeln("</dc:creator>");
filTmpl.writeln("</rdf:Description>");
filTmpl.writeln("</rdf:RDF>");
filTmpl.writeln("</x:xmpmeta>");
fResult = filTmpl.close();
metadata.applyMetadataTemplate(strTmpl, "replace");
filTmpl.remove();
} }
catch(e)
{ fResult = false; }
return fResult;
};
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
#target bridge
if( BridgeTalk.appName == "bridge" ) {
addInfo = new MenuElement("command", "Update Entry Details", "at the end of Thumbnail");
}
addInfo .onSelect = function () {
main();
}
main();
function main(){
var csv = File.openDialog("Please select CSV file.","CSV File:*.csv");
if(csv != null){
var errorlog = new File("~/ErrorLog.txt");
errorlog.open('w');
errorlog.writeln("These documents have not been updated");
csv.open("r");
while(!csv.eof){
strInputLine = csv.readln();
if (strInputLine.length > 3) { // Make sure it isn't a blank line
strInputLine = strInputLine.replace(/\\/g,'/'); //Change backslash to forward slash.
inputArray = strInputLine.split(",");
var csvFile = new File(inputArray[0]);
var title = inputArray[1];
var author = inputArray[2];
if(!csvFile.exists) errorlog.writeln(decodeURI(csvFile) + " does not exist");
if(csvFile.exists){ //Check if file exists
item = new Thumbnail(csvFile);
md =item.synchronousMetadata;
var result =addTitleAuthor(md,inputArray[1],inputArray[2]);
if(!result) errorlog.writeln(decodeURI(csvFile) + " Unable to apply template");
}
}
}
}
errorlog.close();
errorlog.execute();
}
function addTitleAuthor(metadata, Title, Author)
{
var strTmpl = "TempTmpl";
var strUser = Folder.userData.absoluteURI;
var filTmpl = new File(strUser + "/Adobe/XMP/Metadata Templates/" + strTmpl + ".xmp");
var fResult = false;
try
{ if (filTmpl.exists)
filTmpl.remove();
fResult = filTmpl.open("w");
if (fResult)
// CS3
{
//CS3
//filTmpl.writeln("<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"Adobe XMP Core 4.1-c037 46.282696, Mon Apr 02 2007 18:36:42 \">");
//CS2
filTmpl.writeln("<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"3.1.2-113\">");
filTmpl.writeln("<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">");
filTmpl.writeln("<rdf:Description rdf:about=\"\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">");
filTmpl.writeln("<dc:title>");
filTmpl.writeln("<rdf:Alt>");
filTmpl.writeln("<rdf:li xml:lang=\"x-default\">"+Title+"</rdf:li>");
filTmpl.writeln("</rdf:Alt>");
filTmpl.writeln("</dc:title>");
filTmpl.writeln("<dc:creator>");
filTmpl.writeln("<rdf:Seq>");
filTmpl.writeln("<rdf:li>" + Author + "</rdf:li>");
filTmpl.writeln("</rdf:Seq>");
filTmpl.writeln("</dc:creator>");
filTmpl.writeln("</rdf:Description>");
filTmpl.writeln("</rdf:RDF>");
filTmpl.writeln("</x:xmpmeta>");
fResult = filTmpl.close();
metadata.applyMetadataTemplate(strTmpl, "replace");
filTmpl.remove();
} }
catch(e)
{ fResult = false; }
return fResult;
};
Copy link to clipboard
Copied
Copy link to clipboard
Copied