Skip to main content
Adobe Photoshop Family

252 Messages

 • 

4K Points

Fri, Jul 22, 2016 6:24 PM

Not a problem

Photoshop CC 2015.5: Script Metadata assigment error

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 ); 
};

Responses

252 Messages

 • 

4K Points

4 years ago

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.

34 Messages

 • 

1.1K Points

4 years ago

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

252 Messages

 • 

4K Points

4 years ago

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? 

252 Messages

 • 

4K Points

3 years ago

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";

1K Messages

 • 

17K Points

3 years ago

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.

631 Messages

 • 

9.6K Points

2 years ago

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...