Filename + code to metadata *Solved*

Upload Photoshop Scripts, download Photoshop Scripts, Discussion and Support of Photoshop Scripts

Moderators: Tom, Kukurykus

BuckeyeFan

Filename + code to metadata *Solved*

Post by BuckeyeFan »

This was a problem that you guys helped me solve a few years ago (old thread is here: bb/viewtopic.php?f=18&t=2917)
The script worked fine.
However I haven't used it in a couple years and went back to use it with no success. I was in CS5, however at the time of the thread I was in CS4. I installed cs4 and tried to run script again with no luck. I haven't changed anything. Am i missing something?
For those who don't want to bother reading the old thread, I'm using this script to insert some code into the description field and insert the filename into that code.

Here's what I have:
Code: Select allvar f = new File('~/Desktop/test.jpg');
var fName = decodeURI( f.name).match(/(.*)(\.[^\.]+)/)[0];
var payPalStr = '"<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">'+
'<input type="hidden" name="cmd" value="_s-xclick"> <input type="hidden" name="hosted_button_id" value="8379432">'+
'<table><tr><td><input type="hidden" name="on0" value="Sizes">Sizes</td></tr><tr><td><select name="os0">'+
'<option value="8x10">8x10 $100.00  <option value="11x14">11x14 $300.00 <option value="16x20">16x20 $400.00 </select>'+
'</td></tr> <tr><td><input type="hidden" name="on1" value="Image name"><tr><td><input type="hidden" name="os1" value = "'+ fName +
'"></td></tr></table>  <input type="hidden" name="currency_code" value="USD"> <input type="image" '+
'src="https://www.paypal.com/en_US/i/btn/btn_cart_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> '+
'<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"></form>"';
setDescription( f, payPalStr);

function setDescription( file, descStr ){// File object, String
    try{
        loadXMPLibrary();
        var xmpf = new XMPFile( file.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE );
        var xmp = xmpf.getXMP();
      try{// if no desc  create one
         if( xmp.countArrayItems( XMPConst.NS_DC, "description" ) == 0 ){
            xmp.appendArrayItem( XMPConst.NS_DC, "description", null,
               XMPConst.PROP_IS_ARRAY, XMPConst.ARRAY_IS_ORDERED );
            xmp.insertArrayItem( XMPConst.NS_DC, "description", 1, descStr );
         } else {// just overwrite
            xmp.setArrayItem( XMPConst.NS_DC, "description", 1, descStr );
         }
      } catch(e) {
         unloadXMPLibrary();
         alert("Unable to write description metadata in file.\r" + f + "\r" + e);
      }
      if (xmpf.canPutXMP( xmp )) {
         xmpf.putXMP( xmp );
      }
      xmpf.closeFile( XMPConst.CLOSE_UPDATE_SAFELY );
   }catch(e){
        unloadXMPLibrary();
        return -1;
    }
   unloadXMPLibrary();
}


function loadXMPLibrary(){
   if ( !ExternalObject.AdobeXMPScript ){
      try{
         ExternalObject.AdobeXMPScript = new ExternalObject
                                    ( 'lib:AdobeXMPScript' );
      }catch (e){
         alert( ErrStrs.XMPLIB );
         return false;
      }
   }
   return true;
}
function unloadXMPLibrary(){
   if( ExternalObject.AdobeXMPScript ) {
      try{
         ExternalObject.AdobeXMPScript.unload();
         ExternalObject.AdobeXMPScript = undefined;
      }catch (e){
         alert( ErrStrs.XMPLIB );
      }
   }
}
Paul MR

Filename + code to metadata *Solved*

Post by Paul MR »

This might help...

Code: Select allvar f = File("/c/captures/a.jpg");
setDescription(f,"My new description");

function setDescription( file, descStr ){
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, "description");
        xmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default", descStr );
      if (xmpf.canPutXMP( xmp )) {
         xmpf.putXMP( xmp );
      }
      xmpf.closeFile( XMPConst.CLOSE_UPDATE_SAFELY );
}
BuckeyeFan

Filename + code to metadata *Solved*

Post by BuckeyeFan »

Paul,
sorry for the late reply on this. I got sidetracked by other projects I had to put above this one. The function that you sent over, should that replace all three functions that I was using in my old script?
Whenever I run it from ESTK I get "File or Folder does not exist" for line Code: Select allif ( !ExternalObject.AdobeXMPScript ) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
What file is it even looking for?
BuckeyeFan

Filename + code to metadata *Solved*

Post by BuckeyeFan »

I got it. This is what I ended up with.
Code: Select allvar docRef = activeDocument;
var fName = docRef.name;
      fName = fName.split( "." );
if ( fName.length > 1 ) {
         fName.length--;
      }
      fName = fName.join(".");
var payPalStr ='<form target="paypal"action="https://www.paypal.com/cgi-bin/webscr"method="post">'+
'<input type="hidden" name="cmd" value="_s-xclick"><input type="hidden" name="hosted_button_id"value="8477085">'+
'<table><tr><td><input type="hidden" name="on0" value="Choose Your Print Size:">Choose Your PrintSize:</td></tr><tr><td><select name="os0">'+
'<option value="5x7">5x7 $25.00<option value="5x7 Mounted">5x7 Mounted $35.00<option value="8x10">8x10 $45.00<option value="8x10 Mounted">8x10 Mounted $60.00<option value="11x14">11x14 $70.00<option value="11x14 Mounted">11x14 Mounted $85.00</select>'+
'</td></tr><tr><td><input type="hidden" name="on1" value="'+fName +'">'+
'<tr><td><input type="hidden"name="os1"value="scenic-008.jpg"></td></tr></table><input type="hidden" name="currency_code" value="USD">'+
'<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit"alt="PayPal - The safer, easier way to pay online!">'+
'<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"></form>';


app.activeDocument.info.caption =payPalStr;
app.activeDocument.info.title = fName;