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.
adding text to a keyword along wih file name...
adding text to a keyword along wih file name...
i hope you don't mind me continuing to use this thread instead of starting a new at the Photoshop script section.. if so i will kindly move over .
Here's my starting point for the Photoshop script..
Code: Select all// Save the current preferences
var startDisplayDialogs = app.displayDialogs
// Set Adobe Photoshop CS4 to use pixels and display no dialogs
app.displayDialogs = DialogModes.NO
// ask the user for the input and output folders
var inputFolder = Folder.selectDialog("Select a folder to tag")
var outputFolder = Folder.selectDialog("Select a folder for the output files")
// see if we got something interesting from the dialog
if (inputFolder != null && outputFolder != null) {
// get all the files found in this folder
var fileList = inputFolder.getFiles()
// save the outputs in JPEG
var jpegOptions = new JPEGSaveOptions()
// set the jpeg quality really low so the files are small
jpegOptions.quality = 10
// open each one in turn
for (var i = 0; i < fileList.length; i++) {
// The fileList includes both folders and files so open only files
if (fileList instanceof File && fileList.hidden == false) {
// get a reference to the new document
var docRef = open(fileList)
// tag all of the documents with photo shoot information
docRef.info.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="8430607">'+
'<table><tr><td><input type="hidden" name="on0" value="Sizes">Choose a Print Size:</td></tr><tr><td><select name="os0"><option value="5x7 - Loose Paper">5x7 - Loose Paper $25.00<option value="5x7 - Mounted">5x7 - Mounted $35.00<option value="8x10 - Loose Paper">8x10 - Loose Paper $45.00<option value="8x10 - Mounted">8x10 - Mounted $60.00<option value="11x14 - Loose Paper">11x14 - Loose Paper $70.00<option value="11x14 - Mounted">11x14 - Mounted $85.00</select> </td></tr>'+
'<tr><td><input type="hidden" name="on1" value="Image name"><tr><td><input type="hidden" name="os1"'+ 'value="'+ app.activeDocument.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>';
// flatten because we are saving to JPEG
docRef.flatten()
// go to 8 bit because we are saving to JPEG
docRef.bitsPerChannel = BitsPerChannelType.EIGHT
// save and close
docRef.saveAs(new File(outputFolder + "/Output" + i + ".jpg"), jpegOptions)
// don’t modify the original
docRef.close(SaveOptions.DONOTSAVECHANGES)
}
}
}
// Reset the application preferences
app.displayDialogs = startDisplayDialogs
obivously taken from the Java script guide, just modifyed to supposdly only change the description. I ran this and nothing happened in the description field.
Is docRef.info.description even the correct string to get to the description field?
Also i would like to save over the current files, not resave anywhere else.
thx.
Here's my starting point for the Photoshop script..
Code: Select all// Save the current preferences
var startDisplayDialogs = app.displayDialogs
// Set Adobe Photoshop CS4 to use pixels and display no dialogs
app.displayDialogs = DialogModes.NO
// ask the user for the input and output folders
var inputFolder = Folder.selectDialog("Select a folder to tag")
var outputFolder = Folder.selectDialog("Select a folder for the output files")
// see if we got something interesting from the dialog
if (inputFolder != null && outputFolder != null) {
// get all the files found in this folder
var fileList = inputFolder.getFiles()
// save the outputs in JPEG
var jpegOptions = new JPEGSaveOptions()
// set the jpeg quality really low so the files are small
jpegOptions.quality = 10
// open each one in turn
for (var i = 0; i < fileList.length; i++) {
// The fileList includes both folders and files so open only files
if (fileList instanceof File && fileList.hidden == false) {
// get a reference to the new document
var docRef = open(fileList)
// tag all of the documents with photo shoot information
docRef.info.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="8430607">'+
'<table><tr><td><input type="hidden" name="on0" value="Sizes">Choose a Print Size:</td></tr><tr><td><select name="os0"><option value="5x7 - Loose Paper">5x7 - Loose Paper $25.00<option value="5x7 - Mounted">5x7 - Mounted $35.00<option value="8x10 - Loose Paper">8x10 - Loose Paper $45.00<option value="8x10 - Mounted">8x10 - Mounted $60.00<option value="11x14 - Loose Paper">11x14 - Loose Paper $70.00<option value="11x14 - Mounted">11x14 - Mounted $85.00</select> </td></tr>'+
'<tr><td><input type="hidden" name="on1" value="Image name"><tr><td><input type="hidden" name="os1"'+ 'value="'+ app.activeDocument.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>';
// flatten because we are saving to JPEG
docRef.flatten()
// go to 8 bit because we are saving to JPEG
docRef.bitsPerChannel = BitsPerChannelType.EIGHT
// save and close
docRef.saveAs(new File(outputFolder + "/Output" + i + ".jpg"), jpegOptions)
// don’t modify the original
docRef.close(SaveOptions.DONOTSAVECHANGES)
}
}
}
// Reset the application preferences
app.displayDialogs = startDisplayDialogs
obivously taken from the Java script guide, just modifyed to supposdly only change the description. I ran this and nothing happened in the description field.
Is docRef.info.description even the correct string to get to the description field?
Also i would like to save over the current files, not resave anywhere else.
thx.
adding text to a keyword along wih file name...
I wonder if you could try this from ESTK
NB: It is for CS4 only!
Code: Select all#target bridge
// CS4 Only!
addHTMLtoDescription();
function addHTMLtoDescription(){
if( xmpLib == undefined ) {
if( Folder.fs == "Windows" )
{var pathToLib = Folder.startup.fsName + "/AdobeXMPScript.dll";}
else {var pathToLib = Folder.startup.fsName + "/AdobeXMPScript.framework";}
var libfile = new File( pathToLib );
var xmpLib = new ExternalObject("lib:" + pathToLib );
}
var sels = app.document.selections;
for(var a =0; a<sels.length;a++){
var thumb = sels[a];
if(thumb.hasMetadata && sels[a].type == "file"){
var HTMLstr = '"<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 +
'"></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>"';
var selectedFile = thumb.spec;
var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
var myXmp = myXmpFile.getXMP();
myXmp.deleteProperty(XMPConst.NS_DC, "description");
myXmp.appendArrayItem(XMPConst.NS_DC, "description", HTMLstr, 0,XMPConst.ARRAY_IS_ORDERED);
if (myXmpFile.canPutXMP(myXmp)) {
thumb.metadata = new Metadata(myXmp.serialize() );
myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}
}
}
}
NB: It is for CS4 only!
Code: Select all#target bridge
// CS4 Only!
addHTMLtoDescription();
function addHTMLtoDescription(){
if( xmpLib == undefined ) {
if( Folder.fs == "Windows" )
{var pathToLib = Folder.startup.fsName + "/AdobeXMPScript.dll";}
else {var pathToLib = Folder.startup.fsName + "/AdobeXMPScript.framework";}
var libfile = new File( pathToLib );
var xmpLib = new ExternalObject("lib:" + pathToLib );
}
var sels = app.document.selections;
for(var a =0; a<sels.length;a++){
var thumb = sels[a];
if(thumb.hasMetadata && sels[a].type == "file"){
var HTMLstr = '"<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 +
'"></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>"';
var selectedFile = thumb.spec;
var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
var myXmp = myXmpFile.getXMP();
myXmp.deleteProperty(XMPConst.NS_DC, "description");
myXmp.appendArrayItem(XMPConst.NS_DC, "description", HTMLstr, 0,XMPConst.ARRAY_IS_ORDERED);
if (myXmpFile.canPutXMP(myXmp)) {
thumb.metadata = new Metadata(myXmp.serialize() );
myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}
}
}
}
adding text to a keyword along wih file name...
I was going to suggest using the XMPlib. I see that Paul has beat me to it.
Below is my Photoshop version.
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 );
}
}
}
Below is my Photoshop version.
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 );
}
}
}
adding text to a keyword along wih file name...
Paul, Mike... you guys Rock!
I have no clue what you did with the xmp (i think you jumped above my pay grade), but it works like a charm. Thanks!!
I have no clue what you did with the xmp (i think you jumped above my pay grade), but it works like a charm. Thanks!!