Skip to main content
Chris Panny
Inspiring
November 21, 2014
Answered

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

  • November 21, 2014
  • 2 replies
  • 1470 views

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.

This topic has been closed for replies.
Correct answer xbytor2

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;
    if (doc.name == srcname) {
      continue;
    }
    app.activeDocument = doc;
    matchColor(srcname);
  }

  app.activeDocument = srcdoc;
};

main();


"matchColor.jsx";
//EOF

2 replies

xbytor2Correct answer
Inspiring
December 1, 2014

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;
    if (doc.name == srcname) {
      continue;
    }
    app.activeDocument = doc;
    matchColor(srcname);
  }

  app.activeDocument = srcdoc;
};

main();


"matchColor.jsx";
//EOF

c.pfaffenbichler
Community Expert
Community Expert
November 21, 2014

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.

Chris Panny
Inspiring
November 21, 2014

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 );

It's only an island if you look at it from the water.
c.pfaffenbichler
Community Expert
Community Expert
November 23, 2014

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")}

};