adding text to a keyword along wih file name...

General Discussion of Scripting for Adobe Bridge

Moderators: Tom, Kukurykus

BuckeyeFan

adding text to a keyword along wih file name...

Post by BuckeyeFan »

this is my first try at Bridge scripting and i'm loss. I want to add a line of text (which is actually html) to the description field of the images' metadata. And to make matters worse i want to use the images' name in the middle of the text. I basically started by using Mike's code that i found on here for taking the file name and adding it to the 'source' field.
Code: Select all#target bridge

addNametoMeta = {};

addNametoMeta.execute = function(){   
  var sels = app.document.selections;   
  for (var i = 0; i < sels.length; i++){

var md = sels.synchronousMetadata;
    md.namespace = "http://ns.adobe.com/photoshop/1.0/";
    md.Description = "<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 = " sels.name "></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>";;
   }
}

// this script only works in bridge
if (BridgeTalk.appName == "bridge"){

  var menu = MenuElement.create( "command", "Save Filename in Metadata", "at the end of Tools");
  menu.onSelect = addNametoMeta.execute;
}
except just having Code: Select allmd.Source = sels.name
i have Code: Select allmd.Description = "my line of code" sels.name "the rest of the code"

is it possible to do what i want it to do? can you point me in the right direction? I also realized that Extendscript wants to recognize all the html i want in the description field as code and not just text. and of course as i'm sure you will see, the script doesn't work at all in Bridge.

i'm trying to avoid having to create 200 paypal buttons for a website i'm creating using SiteGrinder. If i can jsut copy one button over and over and have this script dynamically fill in my hidden input box, it will send me the file's name witht he order rather than having to create 200 separate buttons with each image's name filled in.
thanks for any help
____________________________________________________________-----
----------------------------------------------------------------------------------
update.. i tried hacking up a script i found online. to get this.
Code: Select all#target bridge
if ( app.name == "bridge"  && app.version[0] == '3' )
{


// Create main menu item
   
   var menu = new MenuElement( "menu", "Filename to Metadata cart", "at the end of Tools", "g2mMenu");
   var g2tCommand =  new MenuElement("command", "click here", "at the end of g2mMenu");
//-----------------------------------------------------------------------
//Submenu for filename to iptc title
   g2tCommand.onSelect = function(m)
      {
      var getFolderChildren = true ;
      var filesOnly = true ;
      var thumbs = app.document.selections;
      for ( var i = 0; i < thumbs.length; i++ )
      { var thumb = thumbs;
         var md = thumb.synchronousMetadata;
         md.namespace ="http://ns.adobe.com/photoshop/1.0/";
         md.Title = "<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=" thumb.name "maxlength="60"></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>";   
      }
         Window.alert ("Done " + i + " records");
      }; 

//closing brace
}

i still cannot get the script to recognize the html as text and not code. any way to do this? I can use this script to do something like md.Title="Hello World" However, i cannot change the description with md.Description="Hello World.
Paul MR

adding text to a keyword along wih file name...

Post by Paul MR »

Give this a try....
Code: Select all#target bridge   
   if( BridgeTalk.appName == "bridge" ) { 
addFileName = MenuElement.create("command", "Add FileName to Description", "at the end of Thumbnail");
}
addFileName.onSelect = function () {
     addFileNameToDescription();
     }
function addFileNameToDescription(){
var sels = app.document.selections;
  for (var i = 0; i < sels.length; i++){
var md = sels.synchronousMetadata;
var str = '"<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 = "'+ sels.name +
'"></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>"';
    md.namespace = "http://purl.org/dc/elements/1.1/";
    md.description = str;
  }
}
BuckeyeFan

adding text to a keyword along wih file name...

Post by BuckeyeFan »

well that script didn't work. but i took the html part from yours and added to the other one i had and that did the trick. i missed the single quote marks.
thanks.

_________________-

is the Description field a filed you cannot write to? i can get the script to copy to the Title, but not the Description field. I have tried "Description" and "description" any other ideas?
Paul MR

adding text to a keyword along wih file name...

Post by Paul MR »

I have tested the code in CS3 and CS4 and it does put the information in the description field.

Once the script is loaded select your documents and use the "Right Click Menu" and select "Add FileName to Description"

Then check you description fields.
BuckeyeFan

adding text to a keyword along wih file name...

Post by BuckeyeFan »

Paul,
i just tried again and it's still not working for me. Could it be having an issue with another script i have installed?
I really want it to work.. hmmmmmm
i'll try Cs3 on my other machine when i get home as well. I don't have any xtra scripts installed with that.
Paul MR

adding text to a keyword along wih file name...

Post by Paul MR »

There can be problems if you have the same name used in your scripts.
You could allways test it direct from ESTK (select docs first)
Code: Select all#target bridge 
addFileNameToDescription();

function addFileNameToDescription(){
var sels = app.document.selections;
  for (var i = 0; i < sels.length; i++){
var md = sels.synchronousMetadata;
var str = '"<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 = "'+ sels.name +
'"></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>"';
    md.namespace = "http://purl.org/dc/elements/1.1/";
    md.description = str;
  }
}
Mike Hale

adding text to a keyword along wih file name...

Post by Mike Hale »

I would suggest renaming the function either way as the function name no longer reflects what the function does.
BuckeyeFan

adding text to a keyword along wih file name...

Post by BuckeyeFan »

it worked!! Well at least it worked in Bridge cs3. I have to restart bridge for it to show it though. I'm going to keep tinkering to get to work in CS4, but this is good enough for what i need. You just saved me hours and hours and hours of work. Thanks guys!

--------------

well it seemed to work. It works on some files but not others.
It seems like it works once and that's it. I.E. I changed something in what i wanted to right to the description. Well i cleared the old description and ran the script again and it didn't work the next time.????
as a side note.. is there a way to do this through Photoshop instead of Bridge?
BuckeyeFan

adding text to a keyword along wih file name...

Post by BuckeyeFan »

well i learned that there is a bug in Bridge, dealing with editing the metadata multiple times. Particularly that after you edit it once, it starts writing to an xmp file after that and no longer directly to the file.
So for what i want to work, i have to edit the metadata in photoshop, which always saves directly to the file.
Guess i'm back to the PS scripts.....
Mike Hale

adding text to a keyword along wih file name...

Post by Mike Hale »

Which version of Photoshop are you using?

If it's not CS4 you have to use Bridge or some other app like Exiftools to write metadata with Photoshop.