6 Replies Latest reply on May 16, 2014 3:20 AM by Nuwaus

    Photoshop CC foregroundColor eventlistener

    petrij_4567 Level 1

      I'm making a color wheel panel and it's almost done. What I still need is to create an eventlistener for when foreground or background color is changed.

       

      I know that I can get the foreground color with:

      _Adobe.JSXInterface.app.foregroundColor.rgb

       

      BUT does anybody know how to create an eventlistener that tells me when it's changed?

        • 1. Re: Photoshop CC foregroundColor eventlistener
          Michael L Hale Level 5
          try {
            if (arguments.length >= 2) {
              var desc = arguments[0];
              var event = arguments[1];
              if (event == charIDToTypeID('setd')) {
                var ref = desc.getReference(charIDToTypeID('null'));
                var cls = ref.getDesiredClass();
                if (cls == charIDToTypeID('Clr ')) {
                  var property = ref.getProperty();
                  if(property == charIDToTypeID('FrgC') ){
                      alert('foreground color changed');
                   }
                }
              }
            }
          } catch (e) {}
          
          1 person found this helpful
          • 2. Re: Photoshop CC foregroundColor eventlistener
            petrij_4567 Level 1

            Michael L Hale wrote:

             

            try {
              if (arguments.length >= 2) {
                var desc = arguments[0];
                var event = arguments[1];
                if (event == charIDToTypeID('setd')) {
                  var ref = desc.getReference(charIDToTypeID('null'));
                  var cls = ref.getDesiredClass();
                  if (cls == charIDToTypeID('Clr ')) {
                    var property = ref.getProperty();
                    if(property == charIDToTypeID('FrgC') ){
                        alert('foreground color changed');
                     }
                  }
                }
              }
            } catch (e) {}
            

            Thank you for reply!

             

            As I understand it, that's the check I have to do when the event is triggered. But what I was looking for here is the event code that triggers your example code.

             

            For example..

            The example code could be in a function like this.

            function onPSForegroundColorChanged() { try {  if (arguments.length...... } catch(e) }

             

            Then I would have to add an event listener somewhere that would trigger this function when foreground color is being changed?

            or did I miss something?

            • 3. Re: Photoshop CC foregroundColor eventlistener
              Michael L Hale Level 5

              The code I posted is an example of an event script that tests for foregroundColor change. When installed as a notifier it will run when the user changes the foregroundColor using the colorPicker or eyedropper. There may be other ways to change the color you will need to account for. You should of course replace the alert with more useful code.

               

              One way to install the event handler would be:

              if(!app.notifiersEnabled) app.notifiersEnabled =  true;// make sure notifier are enabled
              var hasEvent = false;// flag for event test
              for(var e = 0;e<app.notifiers.length;e++){// search the notifier for the event
                 if(app.notifiers[e].event == 'setd') hasEvent = true;// if found set flag
              }
              if(!hasEvent) {// if event not found, install
                 var eventFile = new File("~/desktop/setd listener.jsx");// replace with path to where you saved the event handler posted above
                 app.notifiers.add( "setd", eventFile, charIDToTypeID('Clr '));// event, jsxFile, psClass. Adding the class argument will limit when PS fires the event
                 // by including the class argument PS will only fire the event script if the event uses the color class. That should improve performance by not running the
                 // the event script everytime a 'setd' event happens
              }
              
              1 person found this helpful
              • 4. Re: Photoshop CC foregroundColor eventlistener
                petrij_4567 Level 1

                Thank you, that was exactly what I was looking for.

                 

                Wierd though that for some reason I can not use that File()

                var eventFile = new File("test.jsx");

                 

                It just keeps giving me TypeError: Result of expression 'File'[[object FileConstructor]] is not a constructor.

                 

                Maybe I'm missing some import file or something..

                • 5. Re: Photoshop CC foregroundColor eventlistener
                  Michael L Hale Level 5

                  From the code in your original post it looks like you are using the CS-SDK( or Panel SDK ). I don't know how to create a file object with ActionScript. You may want to ask in the CS-SDK user forum.

                  • 6. Re: Photoshop CC foregroundColor eventlistener
                    Nuwaus

                    Can you please tell me where to put these codes?