Skip to main content
Inspiring
November 11, 2016
Answered

Suspend History States

  • November 11, 2016
  • 2 replies
  • 6596 views

Is there a way to stop the steps in a script showing up in the history.

I have seen other posts talking about suspendHistory but `i am not that familiar with how to use that call

This topic has been closed for replies.
Correct answer DBarranca

Say that you need to run the following code:

var doc = app.activeDocument;

var lay = doc.activeLayer;

var dup = lay.duplicate();

dup.name = "Friday";

dup.applyGaussianBlur (20);

alert("Too much wine");

This leaves 3 steps in the History palette.

The suspendHistory() method accepts two params: the string that is going to appear in the History palette in lieu of the 3 "normal" steps; and the 6 lines of ExtendScript I've written above. E.g.

app.activeDocument.suspendHistory('Swing', 'var doc = app.activeDocument; var lay = doc.activeLayer; var dup = lay.duplicate(); dup.name = "Friday"; dup.applyGaussianBlur (20); alert("Too much wine");'

Usually you won't stick that much code into a string, so the following is the usual pattern:

function main() {

  var doc = app.activeDocument;

  var lay = doc.activeLayer;

  var dup = lay.duplicate();

  dup.name = "Friday";

  dup.applyGaussianBlur (20);

  alert("Too much wine");

}

app.activeDocument.suspendHistory ("Swing", "main()");

Hope this helps,

Davide

2 replies

Participant
May 2, 2020

This worked to get rid of all the layer states from my script but now my script runs again once it completes. What am I doing wrong?

JJMack
Community Expert
Community Expert
May 2, 2020

What would cause your script to be run as second time?  Post your modified  script the changed code for some reason is now  may be running the main function twice. The question was written three years ago so I assuming you have just just now  modicied your existing sectipt to suspend history.  Which is done by using fumction is there more then one use of that function in the scripts code? 

JJMack
Participant
May 2, 2020

Yeah I figured it out just now, when I turned my action into a script file (using another script) it was adding this at the end of the code. It ran fine when I tried it at first but was leaving history states and when I added the line of code to suspend history it made the script re-run not sure why so I just deleted this section and added the code to the end to remove the history states and now it works.

};

//=========================================
// Frequency.main
//=========================================
//

Frequency.main = function () {
Frequency();
}

Frequency.main();

// EOF

"Frequency.jsx"
// EOF
DBarranca
DBarrancaCorrect answer
Legend
November 11, 2016

Say that you need to run the following code:

var doc = app.activeDocument;

var lay = doc.activeLayer;

var dup = lay.duplicate();

dup.name = "Friday";

dup.applyGaussianBlur (20);

alert("Too much wine");

This leaves 3 steps in the History palette.

The suspendHistory() method accepts two params: the string that is going to appear in the History palette in lieu of the 3 "normal" steps; and the 6 lines of ExtendScript I've written above. E.g.

app.activeDocument.suspendHistory('Swing', 'var doc = app.activeDocument; var lay = doc.activeLayer; var dup = lay.duplicate(); dup.name = "Friday"; dup.applyGaussianBlur (20); alert("Too much wine");'

Usually you won't stick that much code into a string, so the following is the usual pattern:

function main() {

  var doc = app.activeDocument;

  var lay = doc.activeLayer;

  var dup = lay.duplicate();

  dup.name = "Friday";

  dup.applyGaussianBlur (20);

  alert("Too much wine");

}

app.activeDocument.suspendHistory ("Swing", "main()");

Hope this helps,

Davide

IanBarberAuthor
Inspiring
November 11, 2016

Thank you Davide, very well explained. I fully understand it now