Skip to main content
Known Participant
October 31, 2008
Question

Can I automate the writing of XMP metadata into JPEG and TIFF files?

  • October 31, 2008
  • 91 replies
  • 11728 views
I have written an ASP.NET 3.5 website application on behalf of an annual international photographic competition. Entrants will be uploading digital photos in either JPEG or TIFF format. Ideally, I would write entrant identity and image title information into the XMP metadata for each image immediately after upload - but so far, I have failed to find any way to do this in ASP.NET.

Thousands of images are involved, so I need to find a way to automate the metadata insertion, perhaps with some sort of script that uses a text file (extracted from the SQL Server database on my website) as the source of the metadata for a batch of images. Is this the sort of task that can be done by writing a script for Bridge CS3? Are there any scripts already in existence that I could use? I am a total beginner in this area.

I use a Win XP PC, though I have a colleague who, I think, has CS3 on his Mac (running under the Leopard OS), so scripts for either platform might be usable.

David
This topic has been closed for replies.

91 replies

Known Participant
November 4, 2008
I've just realised that I mistyped my version of Bridge in my OP. Apologies for the misleading information. I have Bridge CS2, not CS3. Does that perhaps explain my problem?

Obviously, I don't have an Adobe Bridge CS3 folder. Neither do I have an Adobe Bridge CS2 folder. The nearest I have to your quoted path is C:\Program Files\Adobe\Adobe Bridge\ but it doesn't contain AdobeXMPScript.dll (and a search shows that this file is nowhere on my PC).

David
Paul Riggott
Inspiring
November 4, 2008
3poulakia :
Yes I have tested it on my iMac G5 with no problems.

David the dll should be found here..
Could you see if it exists?

C:\Program Files\Adobe\Adobe Bridge CS3\AdobeXMPScript.dll
Known Participant
November 4, 2008
Any idea if this script would run on a MAC CS3 environment?

I keep on trying it but doesn't seem to work

Thank you
michael
Paul Riggott
Inspiring
November 4, 2008
Could you try the last version and see if the DLL ('lib:AdobeXMPScript') is loading?
If it isn't it would explain everything.
Known Participant
November 4, 2008
I re-ran your latest script with a modified version of my CSV file, in which all backslashes were replaced by forward slashes. It still failed. Rather oddly, the error message was exactly the same as before - with backslashes.

David
Paul Riggott
Inspiring
November 4, 2008
You are the man X!

Ok here is another version with a check for the dll.



#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;

}
Paul Riggott
Inspiring
November 4, 2008
I am no expert on these error messages, but looking at file path it is using backslashes, there is some code earlier to try to make them into forward slashes, as on a PC you would have to have a path with TWO backslashes for it to work OR single forward slashes (If that makes sense.

Have you tried just one or two files in the csv file using forward slashes?

If you could try this at least we could rule it out.
Known Participant
November 4, 2008
Paul,
You need to check the results of your loadXMPScript call. The 'no constructor'
message probably means that the DLL didn't get loaded correctly.

-X
Known Participant
November 4, 2008
Hi Paul,
I've just tried your latest script. It fails with the message:

Problem opening xmp for update:-
C:\Documents and Settings\......\MyImage.jpg XMPFile does not have a constructor.

David
Paul Riggott
Inspiring
November 4, 2008
Hi David, I have added some try-catch blocks so it should now indicate where and why it doesn't work.

Please could you try this..



#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;

}
Known Participant
November 4, 2008
Paul,
There are now 3 people who have been unable to get your script to work (i.e. 3poulakia, myself and the person who contacted me by email). It's unlikely that we are all doing something wrong. My best guess is that your script depends on some library or other that you have and we don't.

Any ideas?

David