Tuesday, January 27, 2015

How do I set eyedropper settings using Photoshop ExtendScript (Javascript)?


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



Answer



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.


No comments:

Post a Comment

technique - How credible is wikipedia?

I understand that this question relates more to wikipedia than it does writing but... If I was going to use wikipedia for a source for a res...