Adobe Color Picker

Photoshop Script Snippets - Note: Full Scripts go in the Photoshop Scripts Forum

Moderators: Tom, Kukurykus

Mike Hale

Adobe Color Picker

Post by Mike Hale »

Below is a script from a thread on the Adobe Photoshop Scripting forum.

Thanks to Christoph Pfaffenbichler, Paul Riggott, and Tina Saunders

Code: Select allcolorPicker();
/////////////////////////////////////////////////////////////////
// Function: colorPicker
// Description: Creates a temp solidcolor adjustment layer to
//                let the user set the forground color
//                 
// Usage: colorpicker()
// Input: None
// Return: None
// Dependencies: None
// Notes:             
//////////////////////////////////////////////////////////////////
function colorPicker(){
    // set starting color
var historyState = activeDocument.activeHistoryState;
    var startColor = app.foregroundColor;
var originalUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.activeDocument.selection.select([[0,0],[1,0],[1,1],[0,1]]);
app.preferences.rulerUnits = originalUnits;
    // create colour layer
    CreateSolidLayer();
    // call the color picker
    var desc = new ActionDescriptor();
        var ref = new ActionReference();
        ref.putEnumerated( stringIDToTypeID( "contentLayer" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
    desc.putReference( charIDToTypeID( "null" ), ref );
    var modeDesc = new ActionDescriptor();
        var colorDesc = new ActionDescriptor();
            colorDesc.putDouble( charIDToTypeID( "Rd  " ), startColor.rgb.red );
            colorDesc.putDouble( charIDToTypeID( "Grn " ), startColor.rgb.green );
            colorDesc.putDouble( charIDToTypeID( "Bl  " ), startColor.rgb.blue );
        modeDesc.putObject( charIDToTypeID( "Clr " ), charIDToTypeID( "RGBC" ), colorDesc );
    desc.putObject( charIDToTypeID( "T   " ), stringIDToTypeID( "solidColorLayer" ), modeDesc );
try{
    executeAction( charIDToTypeID( "setd" ), desc, DialogModes.ALL )
}catch(e){}
    // get user's color and set to forground color
    var ref = new ActionReference();
        ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
    var desc = executeActionGet(ref)
    var adjList = desc.getList(stringIDToTypeID('adjustment'));
    var adjDesc = adjList.getObjectValue(0);
    var colorDesc = adjDesc.getObjectValue(stringIDToTypeID('color'));
    var Colour = new SolidColor();
        Colour.rgb.red = colorDesc.getDouble(charIDToTypeID('Rd  '));
        Colour.rgb.green = colorDesc.getDouble(charIDToTypeID('Grn '));
        Colour.rgb.blue = colorDesc.getDouble(charIDToTypeID('Bl  '));
    // restore
activeDocument.activeHistoryState = historyState;
  //  activeDocument.activeLayer.remove();
    app.foregroundColor = Colour;
    }


    function CreateSolidLayer() {
        var startColor = app.foregroundColor;
        var desc = new ActionDescriptor();
            var ref = new ActionReference();
            ref.putClass( stringIDToTypeID('contentLayer') );
        desc.putReference( charIDToTypeID('null'), ref );
            var desc1 = new ActionDescriptor();
                var desc2 = new ActionDescriptor();
                    var desc3 = new ActionDescriptor();
                    desc3.putDouble( charIDToTypeID('Rd  '), startColor.rgb.red );
                    desc3.putDouble( charIDToTypeID('Grn '), startColor.rgb.green );
                    desc3.putDouble( charIDToTypeID('Bl  '), startColor.rgb.blue );
                desc2.putObject( charIDToTypeID('Clr '), charIDToTypeID('RGBC'), desc3 );
            desc1.putObject( charIDToTypeID('Type'), stringIDToTypeID('solidColorLayer'), desc2 );
        desc.putObject( charIDToTypeID('Usng'), stringIDToTypeID('contentLayer'), desc1 );
        executeAction( charIDToTypeID('Mk  '), desc, DialogModes.NO );
};
jugenjury

Adobe Color Picker

Post by jugenjury »

Mike,

Can you explain more of what this does and when it might be used?

From what I can tell it allows the ability to choose a foreground color (and it could easily be adapted to background color also) while in the middle of running a script vs waiting until the script finishes.
Mike Hale

Adobe Color Picker

Post by Mike Hale »

Right, it lets the user pick a color in an interface they are used to while the script is running.

The function can be changed so it returns the color instead of setting the foreground so the color can be used for anything.
jugenjury

Adobe Color Picker

Post by jugenjury »

Mike Hale wrote:Right, it lets the user pick a color in an interface they are used to while the script is running.

The function can be changed so it returns the color instead of setting the foreground so the color can be used for anything.

Great, thanks. I will probably find some fun uses for this.