Skip to main content
Inspiring
July 30, 2010
Répondu

Display the filed instructions (that´s under IPTC Core metadata).

Hi all

I´m new on programing scripts in Photoshop..and tried everything but was not able to change the script below. Let´s explain this script is found at Adobe Photoshop default folder and works to show the Camera Model used to the current image.

Now..the challenge...I want to change the scripts so when you run the it shows a field called Instructions (that´s located in the IPTC Core XMP metadata Tab. (In Photoshop > open an Image > go to File menu > File Info option and see the IPTC Core Tab > Instruction field).

Can anyone please help me to change this lines. It could look very simple for you but it´s actually very difficult to me; This base-script is what I have and works fine to display the camera model:

try {

     var xmpString = activeDocument.xmpMetadata.rawData.toString();

     var tiffModelLength = ('<tiff:Model>').length;

     var tiffModel = xmpString.search( '<tiff:Model>' );

     var tiffModelEnd = xmpString.search( '</tiff:Model>' );

     var tiffModelStr = xmpString.substr( tiffModel + tiffModelLength, tiffModelEnd - tiffModel - tiffModelLength );

     if ( tiffModelStr.length > 0 ) {

          alert( tiffModelStr + localize ( '$$$' ) );

     }

     // check the exif

     var exifModelStr = '';

     var exifData = activeDocument.info.exif;

     for ( var i = 0; i < exifData.length; i++ ) {

          if ( exifData[0] == 'Model' ) {

          }

     }

} // try end

catch( e ) {

// always wrap your script with try/catch blocks so you don't stop production

// remove comments below to see error for debugging

// alert( e );

}

---
Thank you a lot for any help.
Gustavo.
Ce sujet a été fermé aux réponses.
Meilleure réponse par Paul Riggott

Here is one of X's functions that should give you the information..

#target photoshop
var xmp = activeDocument.xmpMetadata.rawData;
var Instructions = parseMetadata(xmp,"photoshop:Instructions");

alert(Instructions);

function parseMetadata(xmp, tag) {
  var re = new RegExp('<' + tag + '>(.+)</' + tag + '>');
  var m = xmp.match(re);
  if (!m) {
    re = new RegExp("<[^:]+:" + tag + ">(.+)</[^:]+:" + tag + '>');
    m = this.xmp.match(re);
  }

  return (m ? m[1] : '');
};

1 commentaire

Paul Riggott
Paul RiggottRéponse
Inspiring
July 30, 2010

Here is one of X's functions that should give you the information..

#target photoshop
var xmp = activeDocument.xmpMetadata.rawData;
var Instructions = parseMetadata(xmp,"photoshop:Instructions");

alert(Instructions);

function parseMetadata(xmp, tag) {
  var re = new RegExp('<' + tag + '>(.+)</' + tag + '>');
  var m = xmp.match(re);
  if (!m) {
    re = new RegExp("<[^:]+:" + tag + ">(.+)</[^:]+:" + tag + '>');
    m = this.xmp.match(re);
  }

  return (m ? m[1] : '');
};

Inspiring
July 30, 2010

Paul

You are my new hero.

Thank you a lot for this.

It´s quite perfect.

All my best

Gustavo.