0

Is there a way to set Photoshop's eyedropper settings (sample size, sample, show sample ring) in a script? Or, failing that, use the script to find out what the current settings are? Thanks.

Eyedropper settings in photoshop

2 Answers 2

2

Based on some googling, it sure doesn't seem like it's directly possible. However, you can use scripting listener/action manager to change the tool preset.

So... maybe you could make a tool preset for each sample size you need and change the tool preset instead.

This method does have a few major drawbacks:

  • One downside is that it saves all tool settings for the eyedropper, so if you need different sample layer settings too, you'd need to create even more presets...
  • Not to mention the tool preset file .tpl would need to travel with the script, or you'd get issues down the line.
  • A little bit of a drawback is that unless your tool preset list is showing presets for all tools, which it likely isn't or you can't assume it is, you can select a preset only if the correct tool is first selected.

Here's code that selects the eyedropper tool and activates a preset that I named 3 by 3 Average (All Layers).

selectTool("eyedropperTool");
selectToolPreset("3 by 3 Average (All Layers)");

function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };

function selectTool( toolName ) {

  var desc78 = new ActionDescriptor();
    var ref38 = new ActionReference();
    ref38.putClass( sTID( toolName ) );
  desc78.putReference( cTID('null'), ref38 );
  desc78.putBoolean( sTID('dontRecord'), true );
  desc78.putBoolean( sTID('forceNotify'), true );
  executeAction( cTID('slct'), desc78, DialogModes.NO );

};

function selectToolPreset( toolPresetName ) {

  var desc75 = new ActionDescriptor();
    var ref36 = new ActionReference();
    ref36.putName( sTID('toolPreset'), toolPresetName );
  desc75.putReference( cTID('null'), ref36 );
  executeAction( cTID('slct'), desc75, DialogModes.NO );

};

I used the Xtools script: LastLogEntry.jsx to get the last Scripting Listener entry and clean it up a little.

2

To get a current setting of an eyedropper (switch to eyedropper first using Joonas' selectTool()):

//returns 0 for Point Sample, 1 for 3x3, etc
function getCurrentEyedropperSetting() {
    var ref = new ActionReference();
    ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("tool"));
    ref.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
    return executeActionGet(ref).getObjectValue(stringIDToTypeID("currentToolOptions")).getInteger(stringIDToTypeID("eyeDropperSample"));
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.