Skip to main content
Participant
November 29, 2023
Question

Opacity, flow, hue etc.. on a dial

  • November 29, 2023
  • 4 replies
  • 401 views

Hello everyone,

I'm trying to create a script for brush opacity, hue, flow and other stuff because I want to put those on a dial..

here my script but I get the error 21: undefined is not an object line 5: if (activeTool.kind == ToolKind.BRUSH) {

Anyone can help? Thanks

 

// Get the active brush tool

var activeTool = app.activeTool;

// Check if the active tool is a brush tool

if (activeTool.kind == ToolKind.BRUSH) {

// Get the current opacity of the active brush

var currentOpacity = activeTool.settings.opacity;

// Calculate the new opacity

var newOpacity = currentOpacity - (currentOpacity * 0.05);

// Set the new opacity of the active brush

activeTool.settings.opacity = newOpacity; } else { alert("Please select a brush tool"); }

This topic has been closed for replies.

4 replies

c.pfaffenbichler
Community Expert
Community Expert
December 3, 2023

This should serve as an example of how to get information about the current Tool.  

The screenshot shows the second alert for the Brush Tool for example: 

// based on code by michael l hale;
// 2012, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var appDesc = executeActionGet(ref);
//checkDesc2(appDesc);
alert (typeIDToStringID(executeActionGet(ref).getEnumerationType(stringIDToTypeID('tool'))));
var toolOptions = appDesc.getObjectValue(stringIDToTypeID('currentToolOptions'));
checkDesc2(toolOptions);
};
//////
// by michael l hale;
function checkDesc (theDesc) {
var c = theDesc.count;
var str = '';
for(var i=0;i<c;i++){ //enumerate descriptor's keys
	str = str + 'Key '+i+' = '+typeIDToStringID(theDesc.getKey(i))+': '+theDesc.getType(theDesc.getKey(i))+'\n';
	};
alert("desc\n\n"+str);
};
////// based on code by michael l hale //////
function checkDesc2 (theDesc) {
var c = theDesc.count;
var str = '';
for(var i=0;i<c;i++){ //enumerate descriptor's keys
str = str + 'Key '+i+' = '+typeIDToStringID(theDesc.getKey(i))+': '+theDesc.getType(theDesc.getKey(i))+'\n'+getValues (theDesc, i)+'\n';
};
alert("desc\n\n"+str);
};
////// check //////
function getValues (theDesc, theNumber) {
switch (theDesc.getType(theDesc.getKey(theNumber))) {
case DescValueType.BOOLEANTYPE:
return theDesc.getBoolean(theDesc.getKey(theNumber));
break;
case DescValueType.CLASSTYPE:
return theDesc.getClass(theDesc.getKey(theNumber));
break;
case DescValueType.DOUBLETYPE:
return theDesc.getDouble(theDesc.getKey(theNumber));
break;
case DescValueType.ENUMERATEDTYPE:
return (typeIDToStringID(theDesc.getEnumerationValue(theDesc.getKey(theNumber)))+"_"+typeIDToStringID(theDesc.getEnumerationType(theDesc.getKey(theNumber))));
break;
case DescValueType.INTEGERTYPE:
return theDesc.getInteger(theDesc.getKey(theNumber));
break;
case DescValueType.LISTTYPE:
return theDesc.getList(theDesc.getKey(theNumber));
break;
case DescValueType.OBJECTTYPE:
return (theDesc.getObjectValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getObjectType(theDesc.getKey(theNumber))));
break;
case DescValueType.REFERENCETYPE:
return theDesc.getReference(theDesc.getKey(theNumber));
break;
case DescValueType.STRINGTYPE:
return theDesc.getString(theDesc.getKey(theNumber));
break;
case DescValueType.UNITDOUBLE:
return (theDesc.getUnitDoubleValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getUnitDoubleType(theDesc.getKey(theNumber))));
break;
default: 
break;
};
};

 

Participant
December 7, 2023

Thanks so much for the reply! I'll give it a try for sure

c.pfaffenbichler
Community Expert
Community Expert
December 1, 2023

Do you have any Scripting experience? 

Are you familiar with UXP? 

What kind of Dialog or Panel do you want to create (please post a sketch)? 

c.pfaffenbichler
Community Expert
Community Expert
November 30, 2023

By the way: ESTK Scripts can create modal dialogs (though there are supposedly work-arounds), if you want a non-modal Panel you would need to create a UXP Panel. 

Which would probably be better anyway in the long run as ESTK Scripting appears to be on the way out. 

Participant
November 30, 2023

thanks for the info

c.pfaffenbichler
Community Expert
Community Expert
November 30, 2023

Where did you get »app.activeTool«? 

Participant
November 30, 2023

I used google bard for that..

c.pfaffenbichler
Community Expert
Community Expert
November 30, 2023

activeTool is not a property of app in Photoshop’s DOM, so you seem to have created nonsensical code.