Skip to main content
JJMack
Community Expert
Community Expert
July 22, 2016

P: Script Metadata assignment error

  • July 22, 2016
  • 23 replies
  • 721 views

The  following statement in my script below works in Photoshop version Prior to CC 2015.5 but not in  CC 2015.5 Scripting. 

app.activeDocument.info.instructions = before + after;


The full simple toggle script is here

/* ======================================================================================// 2015  John J. McAssey (JJMack)  http://www.mouseprints.net/
//  
// This script is supplied as is. It is provided as freeware. 
// The author accepts no liability for any problems arising from its use.
//
// This script is designed to Toggle centering guides 
//
// ===================================================================================== */
/*

$$$/JavaScripts/AddRemoveCenterGuides/About=JJMack's AddRemoveCenterGuides.^r^rCopyright 2009 Mouseprints.^r^rRun twice script utility for action.^r^rFirst Run Set Guides on camvas bounds and center.^rSecond Run clears the set guides.
JJMackJJMack's Action Run Twice Utility

*/
if (app.documents.length > 0) app.activeDocument.suspendHistory('ToggleCenterGuides','main()' );
else alert("You must have at least one open document to run this script!"); 
/////////////////////////////////////////////////////////////////////////////////////////// 
function main() {
if (app.activeDocument.info.instructions.indexOf("") == -1 ){ // no footprint fisrt useage 
var orig_ruler_units = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS; // Set the ruler units to PIXELS
try { 
activeDocument.guides.add(Direction.VERTICAL, 0);
activeDocument.guides.add(Direction.VERTICAL, activeDocument.width/4);
activeDocument.guides.add(Direction.VERTICAL, activeDocument.width/2);
activeDocument.guides.add(Direction.VERTICAL, activeDocument.width*3/4);
activeDocument.guides.add(Direction.VERTICAL, activeDocument.width);
activeDocument.guides.add(Direction.HORIZONTAL, 0);
activeDocument.guides.add(Direction.HORIZONTAL, activeDocument.height/4);
activeDocument.guides.add(Direction.HORIZONTAL, activeDocument.height/2);
activeDocument.guides.add(Direction.HORIZONTAL, activeDocument.height*3/4);
activeDocument.guides.add(Direction.HORIZONTAL, activeDocument.height);
  }
// display error message if something goes wrong
catch(e) { alert(e + ': on line ' + e.line, 'Script Error', true); }
app.preferences.rulerUnits = orig_ruler_units; // Reset units to original settings
// put footprint in metadata info instructions
app.activeDocument.info.instructions = app.activeDocument.info.instructions + "" + " Show" + ""; 

else { 
clearGuides();
// Remove footprint from metadata info instructions
before = app.activeDocument.info.instructions.substr(0,app.activeDocument.info.instructions.indexOf(""));
afterOffset = app.activeDocument.info.instructions.indexOf("") + "".length;
after = app.activeDocument.info.instructions.substr(afterOffset, app.activeDocument.info.instructions.length - afterOffset);
//alert ("before = " + before + " after = " + after);
app.activeDocument.info.instructions = before + after;


//////////////////////////////////////////// Action Manager Code to Clear all Guides ///////////////////////////////////
function clearGuides() { 
   var id556 = charIDToTypeID( "Dlt " ); 
       var desc102 = new ActionDescriptor(); 
       var id557 = charIDToTypeID( "null" ); 
           var ref70 = new ActionReference(); 
           var id558 = charIDToTypeID( "Gd  " ); 
           var id559 = charIDToTypeID( "Ordn" ); 
           var id560 = charIDToTypeID( "Al  " ); 
           ref70.putEnumerated( id558, id559, id560 ); 
       desc102.putReference( id557, ref70 ); 
   executeAction( id556, desc102, DialogModes.NO ); 
};
This topic has been closed for replies.

23 replies

Kukurykus
Legend
September 1, 2018
All this theard is alike to mine where Adobe changed some important behaviour that always worked for over 20 years, so I understand you John McAssey. That's why I don't use last release but still CS6 EXTENDED. In my case that's something that they are aware of but seems don't care to fix it if that wasn't done yet (taking into account that bug started with CC 2018):

https://feedback.photoshop.com/photoshop_family/topics/opened-document-s-is-are-invisible-after-comi...
Legend
January 9, 2018
This is a normal part of developing software. APIs change and sometimes break your code. Sorry, JJ, but you come across as way too angry here. Use the sample code that was generously provided to deal with the API change and quit ranting.
JJMack
Community Expert
JJMackCommunity ExpertAuthor
Community Expert
January 9, 2018
This is a bug it brakes existing scripts that have worked for years and are distributed free to many Adobe users.  The only way I can work around Adobe bug is by distributing the Garbage.jsx new and  Open Document event handler for use My scripts use the field as a  scratch pad area the insert and remove their own data.    When the bug bites data is not removed that should be removed and brakes the script.  Adobe allows the field to be set back to garbage so the scripts can continue to remover their data.  The is no need to for me to search all the scripts on my system to find the one the use that field and change their code.   I can not change the code on the Adobe  Photoshop users machines for I do not have a list of them or access to their machines.   Adobe should remove the new designer's bug. Introduce two releases ago.

if (app.activeDocument.info.instructions.indexOf("Garbage") == -1 ) app.activeDocument.info.instructions = app.activeDocument.info.instructions + "Garbage";
JJMack
JJMack
Community Expert
JJMackCommunity ExpertAuthor
Community Expert
January 9, 2018
Jeff If deleting a byline, description, or copyright is BAD why does Photoshop File Info support doing that or let me change theirs to mine. 

This Adobe designer bug is easy to program around,  I just add Garbage to the Metadata info field if Garbage is not there with an open document event handler,  Then my scripts can use the info field as a scratch pad and insert and remove their information correctly.  The scripts will be able to restore the field so their data will be removed not left there by Adobe's designer bug Adobe allows it to be set to Garbage.   Adobe needs a better design process.  Every new release of Photoshop seems to add new bugs one needs to work around.  Adobe needs to treat their customers better Photoshop's quality is sliding downhill. 
JJMack
JJMack
Community Expert
JJMackCommunity ExpertAuthor
Community Expert
June 6, 2017
Official Response  "(deleting a byline, description, or copyright is BAD)."
Jeff That means  Adobe Photoshop is bad  Save For Web does that and Phot shop file info editor let one change that information to whatever one wants.  When can we expect to see Adobe fix these issues?
JJMack
JJMack
Community Expert
JJMackCommunity ExpertAuthor
Community Expert
May 5, 2017
So your answer  is every script that resets a field back to their original state must test to  see if that state is "" and if it is should use your function to get around Adobe bug.  That is poor solution with the event handler work around scripts do not need to be scanned to see if they need to be recorded  to program around Adobe's Bug. No script change is needed.  You are correct "The actual bug is this: activeDocument.info.instructions = ""; // does not work if there is a current string of 1 or more characters for instructions" That should work it worked in prior version of Photoshop.  The proper solution is to fix that bug.   Why did Adobe brake the code? 
JJMack
Tom Ruark
Inspiring
May 5, 2017
One last try: The actual bug is this: activeDocument.info.instructions = ""; // does not work if there is a current string of 1 or more characters for instructions, the workaround is my Set function above
JJMack
Community Expert
JJMackCommunity ExpertAuthor
Community Expert
May 5, 2017
remove the instructions as a work around would remove any user instructions and be a bug not a work around. Adding garbage is a work around for the normal case where the field is empty.  The  work around has an undesired side effect it will leave behind Garbage.  And as you point out dirty the document the first time they are edited.  That in no big deal for new document for they will be dirty soon anyway. Old document will be made dirty when garbage need to be added.
JJMack
Tom Ruark
Inspiring
May 5, 2017
You are assigning "Garbage" on every file. That will make every file dirty. I'm just showing you a way to remove the instructions as a work around instead of the work around you provide. That is all. Here is a script that removes the "complex and interactive" parts for you.

SetInstructionsTo("");
function SetInstructionsTo(inString) {

 if (documents.length == 0) {
    return false;
 }
 
 // bug in Photoshop, use XMP to clear out Instructions
 if (inString.length == 0) {
  var startStr = "<photoshop:Instructions>";
  var endStr = "</photoshop:Instructions>";
  var xmpStr = activeDocument.xmpMetadata.rawData;
  var startI = xmpStr.indexOf(startStr);
  var endI = xmpStr.indexOf(endStr);
  if (startI == -1 || endI == -1) {
    return false;
  }

  endI = endI + endStr.length;
  xmpStr = xmpStr.substr(0,startI) + xmpStr.substr(endI, xmpStr.length);

  activeDocument.xmpMetadata.rawData = xmpStr;

  if (activeDocument.info.instructions.length > 0) {
    return false;
  }

 } else {

 activeDocument.info.instructions = inString;
 
 }

 return true;
 
}
JJMack
Community Expert
JJMackCommunity ExpertAuthor
Community Expert
May 5, 2017
Tom are you ever going to fix the CS4 bugs you wrote me that were assigned to you  to fix.
JJMack