Skip to main content
Chuck Uebele
Community Expert
Community Expert
November 12, 2021
Answered

XMPConst.OPEN_FOR_UPDATE throwing error

  • November 12, 2021
  • 3 replies
  • 1596 views

This short test script used to work getting a files description in Bridge, but now it fails on the line tha has: XMPConst.OPEN_FOR_UPDATE. The error is XMP Exception: OpenFile retuned false. Anyone else having issues with this?

 

 

#target bridge

if (ExternalObject.AdobeXMPScript == undefined) {
    ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
    }

var doc = app.document
var thumbs = doc.selections

for(var i=0;i<thumbs.length;i++){
    
    var tSpec = thumbs[i].spec;
    var testFile = new File(tSpec);

    readTextFile (testFile)
    };//end for thumbs loop

function readTextFile(file){
      var xmpf = new XMPFile(File(file).fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE );
      var xmp = xmpf.getXMP();
      var des = xmp.getProperty(XMPConst.NS_DC, "description").toString();
      alert(des)          

            xmpf.closeFile( XMPConst.CLOSE_UPDATE_SAFELY );
      
      }

 

 

This topic has been closed for replies.
Correct answer Lumigraphics

YES! Some sample code would be wonderful. 


XMPdesc();        
        
        XMPdesc = function(){
            var descThumbs = app.document.selections; //get selected thumbnails
            var newText = 'test'; //replacement text
            if(!descThumbs.length) return; //nothing selected
            for(var a in descThumbs){ //loop through thumbs
                if(!descThumbs[a].container){ //not a folder
                    try{
                        var descMeta = descThumbs[a].synchronousMetadata; //get metadata
                        var descXMP = new XMPMeta(descMeta.serialize()); //serialize
                        alert(descMeta.read(XMPConst.NS_DC, 'description').toString()); //read description
                        descXMP.deleteProperty(XMPConst.NS_DC, 'description'); //delete
                        descXMP.setLocalizedText(XMPConst.NS_DC, 'description', null, 'x-default', newText); //set new description
                        var descUpdatedPacket = descXMP.serialize(XMPConst.SERIALIZE_OMIT_PACKET_WRAPPER | XMPConst.SERIALIZE_USE_COMPACT_FORMAT); //serialize
                        descThumbs[a].metadata = new Metadata(descUpdatedPacket); //write to file
                        }
                    catch(e){
                        alert(e + e.line);
                        }
                    }
                }
            }

3 replies

Kukurykus
Legend
December 12, 2021

The error occurs when you use .toString(). Then as processed file was not closed (by last code line), the Bridge remembered its open state, so next time it couldn't proceed, unless you restarted application. The solution is to change UPDATE to READ (due to your original question):

 

!ExternalObject.AdobeXMPScript && ExternalObject
.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript')

slctns = app.document.selections; while(slctns.length) {
	xmp = new XMPFile(slctns.shift().spec.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ)
	try{alert(xmp.getXMP().getLocalizedText(XMPConst.NS_DC, 'description', 0, 0).toString())}catch(err){}
	xmp.closeFile(XMPConst.CLOSE_UPDATE_SAFELY)
}

 

btw please assign Scripting label to your thread 😉

Chuck Uebele
Community Expert
Community Expert
November 12, 2021

Seems to be working with PSD files, but not raw NEF files.

Legend
November 12, 2021

Because you can't read XMP from a RAW file. You have to use thumbnails not file specs.

 

OP, use thumbnails and synchronousMetadata instead of file spec.

Chuck Uebele
Community Expert
Community Expert
November 12, 2021

Thanks!

gregreser
Legend
November 12, 2021

I am not getting the OpenFile error in Bridge 12.0.0.234

 

Your script worked, except that I didn't get a value for var des = xmp.getProperty(XMPConst.NS_DC, "description").toString();

so I changed it to this:

var des = xmp.getArrayItem(XMPConst.NS_DC, "description",1).toString();

Chuck Uebele
Community Expert
Community Expert
November 12, 2021

Thanks for the update.