Skip to main content
bluebeezle
Inspiring
September 10, 2018
Answered

Setting eyedropper options

  • September 10, 2018
  • 1 reply
  • 1877 views

Hey guys,

Some time ago, I had a question about using javascript to perform a select color range. It works, but it uses whatever sample options were set before running the script. It would be nice if I were able to set the Sample option to "Current Layer" via script.

Is there a way to do that?

This topic has been closed for replies.
Correct answer r-bin

CC2018

// remember old tool

var r = new ActionReference();

r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("tool"));

r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

var curr_tool = executeActionGet(r).getEnumerationType(stringIDToTypeID("tool"));

// select eyedropper tool

var r = new ActionReference();

r.putClass(stringIDToTypeID("eyedropperTool"));

var d = new ActionDescriptor();

d.putReference(stringIDToTypeID("null"), r);

executeAction(stringIDToTypeID("select"), d, DialogModes.NO);

// get and set eyedropper tool options

var r = new ActionReference();

r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("tool"));

r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

var op = executeActionGet(r).getObjectValue(stringIDToTypeID("currentToolOptions"));

op.putInteger(stringIDToTypeID("eyeDropperSample"), 0);      // point sample

op.putInteger(stringIDToTypeID("eyeDropperSampleSheet"), 1); // current layer

var r = new ActionReference();

r.putClass(stringIDToTypeID("eyedropperTool"));

var d = new ActionDescriptor();

d.putReference( stringIDToTypeID( "null" ), r );

d.putObject(stringIDToTypeID("to"), stringIDToTypeID("null"), op);

executeAction(stringIDToTypeID("set"), d, DialogModes.NO);

// select old tool

var r = new ActionReference();

r.putClass(curr_tool);

var d = new ActionDescriptor();

d.putReference(stringIDToTypeID("null"), r);

executeAction(stringIDToTypeID("select"), d, DialogModes.NO);

1 reply

r-binCorrect answer
Brainiac
September 10, 2018

CC2018

// remember old tool

var r = new ActionReference();

r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("tool"));

r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

var curr_tool = executeActionGet(r).getEnumerationType(stringIDToTypeID("tool"));

// select eyedropper tool

var r = new ActionReference();

r.putClass(stringIDToTypeID("eyedropperTool"));

var d = new ActionDescriptor();

d.putReference(stringIDToTypeID("null"), r);

executeAction(stringIDToTypeID("select"), d, DialogModes.NO);

// get and set eyedropper tool options

var r = new ActionReference();

r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("tool"));

r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

var op = executeActionGet(r).getObjectValue(stringIDToTypeID("currentToolOptions"));

op.putInteger(stringIDToTypeID("eyeDropperSample"), 0);      // point sample

op.putInteger(stringIDToTypeID("eyeDropperSampleSheet"), 1); // current layer

var r = new ActionReference();

r.putClass(stringIDToTypeID("eyedropperTool"));

var d = new ActionDescriptor();

d.putReference( stringIDToTypeID( "null" ), r );

d.putObject(stringIDToTypeID("to"), stringIDToTypeID("null"), op);

executeAction(stringIDToTypeID("set"), d, DialogModes.NO);

// select old tool

var r = new ActionReference();

r.putClass(curr_tool);

var d = new ActionDescriptor();

d.putReference(stringIDToTypeID("null"), r);

executeAction(stringIDToTypeID("select"), d, DialogModes.NO);

bluebeezle
Inspiring
September 11, 2018

awesome. thanks!