History snapshot doesn't replace existing one

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: xbytor, Kukurykus, Tom


History snapshot doesn't replace existing one

Post by undavide »

I've put together the a function to make a History Snapshot by name. It's not very much different from the one in XTools (besides the fact I use StringIDs), it just adds the code to replace an existing snapshot - thanks to ScriptingListener:

Code: Select allvar s2t = function(s) {
  return app.stringIDToTypeID(s);

var makeSnapshot = function(snapName) {
  var d1, r1, r2;
  d1 = new ActionDescriptor();
  r1 = new ActionReference();
  r2 = new ActionReference();
  d1.putReference(s2t('target'), r1);
  r2.putProperty(s2t('historyState'), s2t('currentHistoryState'));
  d1.putReference(s2t('from'), r2);
  d1.putString(s2t('name'), snapName);
  d1.putEnumerated(s2t('using'), s2t('historyState'), s2t('fullDocument'));
  d1.putBoolean(s2t('replaceExisting'), true);
  return executeAction(s2t('make'), d1, DialogModes.NO);

try {
    makeSnapshot ("first"); // works
    makeSnapshot ("first"); // error
} catch(e) { alert(e.message) }

But for some reason it fires an error (PS CC, OSX), "The parameters for command “Make” are not currently valid."
In fact, it creates the first snapshot, but seems unable to override an existing one. I've double checked the SL code (I've added a nicer formatting, but even raw SL fails).
What's wrong in there? Should I check in advance for an existing snapshot and remove it?
Thank you!