Is This Possible To Do?

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

Colorguy

Is This Possible To Do?

Post by Colorguy »

Within an Action I have the user make a selection using the color range tool for example. Following the selection I'd like the Action to generate a new Channel (not Layer) with the new foreground color chosen by the user.

So far, this seems impossible to do without including stops to click the Color Chip in the New Channel box, followed by clicking the Foreground Color to change it and so on.

Anyhow, is it possible to write some type of script that uses the "current foreground color" to generate a new Channel?

As you can see by the attached graphic, when the New Channel dialog box appears, it never indicates the current foreground color and a few manual steps are always needed to be implemented which I'd like to avoid by the use of a script if possible.

xbytor

Is This Possible To Do?

Post by xbytor »

Try this:

Code: Select allfunction newChannel() {
  function cTID(s) { return app.charIDToTypeID(s); };
  var fg = app.foregroundColor;

    var desc20 = new ActionDescriptor();
        var desc21 = new ActionDescriptor();
        desc21.putEnumerated( cTID('ClrI'), cTID('MskI'), cTID('SlcA') );
            var desc22 = new ActionDescriptor();
            desc22.putDouble( cTID('Rd  '), fg.rgb.red );
            desc22.putDouble( cTID('Grn '), fg.rgb.green );
            desc22.putDouble( cTID('Bl  '), fg.rgb.blue );
        desc21.putObject( cTID('Clr '), cTID('RGBC'), desc22 );
        desc21.putInteger( cTID('Opct'), 100 );
    desc20.putObject( cTID('Nw  '), cTID('Chnl'), desc21 );
    executeAction( cTID('Mk  '), desc20, DialogModes.NO );
};

newChannel();
Colorguy

Is This Possible To Do?

Post by Colorguy »

Thanks Xbytor....I'll give this a try tomorrow when I get to work. Much appreciated.
Colorguy

Is This Possible To Do?

Post by Colorguy »

Decided to try it out now. It works! Must have played around with that on and off for weeks. I can't thank you enough. You are a scripts wizard my friend. Making a donation to the site now. $20 but maybe you guys can have a few beers on me. Thanks again!