6 Replies Latest reply on Dec 2, 2014 12:30 PM by Chris Panny

    Photoshop uses JavaScript to load open documents into the Match Color command

    Chris Panny Level 1

      Hello,

       

      I am a production artist and I make use of the Match Color command quite a lot in my work. I often have 6-10 Photoshop documents open and one of them is designated as my master document. With this document active, I launch the Match Color command. Inside the Match Color dialogue, I load one of the other open documents into the Source drop-down menu under Image Statistics. I click Ok, and save the master document under a new name. I have to repeat this for all other open documents. Needless to say, it gets tedious.


      I started to write a script to automate this, but I cannot find the syntax for the Match Color. I have the Adobe Photoshop Cs6 Javascript Scripting Reference but have been unable to locate it in this PDF. I tried looking online, but no luck. Does anyone know what syntax to use as well as associated properties / methods?

       

      Thanks for any assistance.

        • 1. Re: Photoshop uses JavaScript to load open documents into the Match Color command
          c.pfaffenbichler Level 9

          Have you tried ScriptingListener.plugin to record AM code?

           

          And quite frankly I don’t consider Match Color a suitable operation for serious image editing as it is destructive.

          • 2. Re: Photoshop uses JavaScript to load open documents into the Match Color command
            Chris Panny Level 1

            What we do is we make seamless images from product photos supplied by retailers in the flooring industry (carpet, tiles, etc). The seamless image gets loaded into a virtual room scene powered by Adobe Scene7. Scene7 takes the seamless image and duplicates it horizontally and vertically, in 3D perspective, so the final rendering looks like one continuous product image. Check this link to see an example:  http://sitesetup.creatingyourspace.com/wlhhbw4/designcenter/vrddesign.aspx?room=2854 The thumbnails on the left side are seamless images. click on one and it will load into the virtual room.

             

            When I make seamless I may encounter 20-50 images of the same product, but different colors. Rather than spend 10-15 minutes per seamless, I make one and then let Match Color do the rest. Match Color is a great tool for this application. If destructive editing were an issue, the layer could simply made into a smart object, but we're not concerned about that.

             

            I did try the javaScript listener. Below is the code it generated. I'm new to JS so I don't understand all of the syntax.

             

            // =======================================================
            var idmatchColor = stringIDToTypeID( "matchColor" );
                var desc7 = new ActionDescriptor();
                var idLght = charIDToTypeID( "Lght" );
                desc7.putInteger( idLght, 100 );
                var idClrR = charIDToTypeID( "ClrR" );
                desc7.putInteger( idClrR, 100 );
                var idFade = charIDToTypeID( "Fade" );
                desc7.putInteger( idFade, 0 );
                var idfsel = charIDToTypeID( "fsel" );
                desc7.putBoolean( idfsel, true );
                var idSrce = charIDToTypeID( "Srce" );
                    var ref5 = new ActionReference();
                    var idLyr = charIDToTypeID( "Lyr " );
                    var idBckg = charIDToTypeID( "Bckg" );
                    ref5.putProperty( idLyr, idBckg );
                    var idDcmn = charIDToTypeID( "Dcmn" );
                    ref5.putName( idDcmn, "4167_13828.jpg" );
                desc7.putReference( idSrce, ref5 );
            executeAction( idmatchColor, desc7, DialogModes.NO );

            • 3. Re: Photoshop uses JavaScript to load open documents into the Match Color command
              c.pfaffenbichler Level 9

              If destructive editing were an issue, the layer could simply made into a smart object, but we're not concerned about that.

              But then Match Color would not work on it, would it?

               

              I'm new to JS so I don't understand all of the syntax.

              A common approach is to wrap the AM code in a function that takes an argument which is then used in the code.

              #target photoshop

              matchColor ("aaa");

              function matchColor (fileName) {

              try {

              // =======================================================

              var idmatchColor = stringIDToTypeID( "matchColor" );

                  var desc7 = new ActionDescriptor();

                  var idLght = charIDToTypeID( "Lght" );

                  desc7.putInteger( idLght, 100 );

                  var idClrR = charIDToTypeID( "ClrR" );

                  desc7.putInteger( idClrR, 100 );

                  var idFade = charIDToTypeID( "Fade" );

                  desc7.putInteger( idFade, 0 );

                  var idfsel = charIDToTypeID( "fsel" );

                  desc7.putBoolean( idfsel, true );

                  var idSrce = charIDToTypeID( "Srce" );

                      var ref5 = new ActionReference();

                      var idLyr = charIDToTypeID( "Lyr " );

                      var idBckg = charIDToTypeID( "Bckg" );

                      ref5.putProperty( idLyr, idBckg );

                      var idDcmn = charIDToTypeID( "Dcmn" );

                      ref5.putName( idDcmn, fileName );

                  desc7.putReference( idSrce, ref5 );

              executeAction( idmatchColor, desc7, DialogModes.NO )

              }

              catch (e) {alert ("no file named "+fileName+" open")}

              };

              • 4. Re: Photoshop uses JavaScript to load open documents into the Match Color command
                Chuck Uebele Adobe Community Professional & MVP

                If your master document changes, then you will most likely want to create a UI with a drop down list of the open file names so that you can easily select the one you want.

                • 5. Re: Photoshop uses JavaScript to load open documents into the Match Color command
                  xbytor2 Level 4

                  Try this:

                   

                  //
                  // MatchColor.jsx
                  // The source image must be the active document at the time this
                  // script is run.
                  //
                  function matchColor(fileName) {
                    function cTID(s) { return app.charIDToTypeID(s); };
                    function sTID(s) { return app.stringIDToTypeID(s); };
                      var desc11 = new ActionDescriptor();
                      desc11.putInteger( cTID('Lght'), 100 );
                      desc11.putInteger( cTID('ClrR'), 100 );
                      desc11.putInteger( cTID('Fade'), 0 );
                      desc11.putBoolean( cTID('fsel'), true );
                          var ref8 = new ActionReference();
                          ref8.putProperty( cTID('Lyr '), cTID('Bckg') );
                          ref8.putName( cTID('Dcmn'), fileName);
                      desc11.putReference( cTID('Srce'), ref8 );
                      executeAction( sTID('matchColor'), desc11, DialogModes.NO );
                  };
                  
                  function main() {
                    if (app.documents.length < 2) {
                      alert("At least 2 images must be open for this script to run.");
                      return;
                    }
                    var srcdoc = app.activeDocument;
                    var srcname = srcdoc.name;
                    var docs = app.documents;
                    var len = docs.length;
                    for (var i = 0; i < len; i++) {
                      var doc = docs[i];
                      if (doc.name == srcname) {
                        continue;
                      }
                      app.activeDocument = doc;
                      matchColor(srcname);
                    }
                    app.activeDocument = srcdoc;
                  };
                  main();
                  
                  "matchColor.jsx";
                  //EOF
                  
                  • 6. Re: Photoshop uses JavaScript to load open documents into the Match Color command
                    Chris Panny Level 1

                    Good point about the smart object not working in this case.

                     

                    Thanks for the code. I'm going to analyze it further so I can understand the logic behind it. I've been reading some Adobe (javaScript) documentation that's been helping me understand how to write effective code. Plus the help I get from people like yourself, I'm optimistic I'll get a good handle on this before long. Thank you!