Help on Generator event

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

tyr

Help on Generator event

Post by tyr »

Hi everyone. Has anyone played with Generator scripts? I have no idea where to look for help: except for several tutorials on Tom Krcha's website I can't find any documentation.

What I'm trying to do is launch JSX code every time the document updates. The problem is that this JS counts as an event and I'm getting an infinite loop. For now I put a timer check but I guess that is an ugly solution, because I don't know what time would take operations on different machines. Does anyone know if there's a different event I can use? Or maybe a community where I can ask this question?

here's my code:
Code: Select all(function () {
   
   "use strict";
   
   var generator;
   var i = 0;
   var lastOnChangeRunDate = getTime();

   function getTime() { return (new Date()).getTime(); }
   
   function init(gen) {
      generator = gen;
      generator.addMenuItem("fp", "test pludsfdfdsin", true, false)
      generator.onPhotoshopEvent("imageChanged", trololo);
      }

      function trololo ( e) {
        if(getTime()-lastOnChangeRunDate<400) return;
        lastOnChangeRunDate = getTime();
        i++;
        var str = "doc = activeDocument; \
              tL= doc.layers[0]; \
                 tL.textItem.contents = "+i
        generator.evaluateJSXString(str);
        }
      
   
   exports.init = init;
   
}());