Skip to main content
Participant
July 11, 2024
Answered

Are these Photoshop script ideas possible?

Hello, I'm looking to get into photoshop scripting but was curious if my ideas are even possible to begin with.
What I'd like to make:


- a hotkey for a specific brush
- a hotkey for alternating between two brush flow settings (e.g. press once = brush flow 20%, press twice = 80%, press again = back to 20%)


Thank you!

c.pfaffenbichler
c.pfaffenbichlerCorrect answer
Community Expert
May 24, 2025
quote

- a hotkey for a specific brush

AM code can be used to select a brush by name. 

To avoid problems when the brush is absent one may want to wrap it in a try-clause. 

// =======================================================
var idselect = stringIDToTypeID( "select" );
    var desc4 = new ActionDescriptor();
    var idnull = stringIDToTypeID( "null" );
        var ref1 = new ActionReference();
        var idbrush = stringIDToTypeID( "brush" );
        ref1.putName( idbrush, "Hard Round 123 1083" );
    desc4.putReference( idnull, ref1 );
executeAction( idselect, desc4, DialogModes.NO );

 

2 replies

c.pfaffenbichler
Community Expert
c.pfaffenbichlerCommunity ExpertCorrect answer
Community Expert
May 24, 2025
quote

- a hotkey for a specific brush

AM code can be used to select a brush by name. 

To avoid problems when the brush is absent one may want to wrap it in a try-clause. 

// =======================================================
var idselect = stringIDToTypeID( "select" );
    var desc4 = new ActionDescriptor();
    var idnull = stringIDToTypeID( "null" );
        var ref1 = new ActionReference();
        var idbrush = stringIDToTypeID( "brush" );
        ref1.putName( idbrush, "Hard Round 123 1083" );
    desc4.putReference( idnull, ref1 );
executeAction( idselect, desc4, DialogModes.NO );

 

Translate
c.pfaffenbichler
Community Expert
Community Expert
May 24, 2025

@ryank45859795 wrote:

- a hotkey for alternating between two brush flow settings (e.g. press once = brush flow 20%, press twice = 80%, press again = back to 20%)


// set brush tool to either 80% or 20% flow;
// 2025, use it at your own risk;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var applicationDesc = executeActionGet(ref);
var theTool = typeIDToStringID(applicationDesc.getEnumerationType(stringIDToTypeID("tool")));
if (theTool == "paintbrushTool") {
var theCurrentToolOptions = applicationDesc.getObjectValue(stringIDToTypeID("currentToolOptions"));
var theFlow = theCurrentToolOptions.getInteger(stringIDToTypeID("flow"));
switch (theFlow) {
case 80:
setBrushToolFlow(20);
break;
case 20:
setBrushToolFlow(80);
break;
default:
setBrushToolFlow(80);
break;
};
};
////////////////////////////////////
function setBrushToolFlow (theFlow) {
(r = new ActionReference()).putProperty(stringIDToTypeID('property'), p = stringIDToTypeID('currentToolOptions'));
r.putEnumerated(stringIDToTypeID('application'), stringIDToTypeID('ordinal'), stringIDToTypeID('targetEnum'));
var tool = executeActionGet(r).getObjectValue(p);
if (tool.hasKey(stringIDToTypeID('brush'))) {
tool.putUnitDouble( stringIDToTypeID( "flow" ), stringIDToTypeID( "percentUnit" ), theFlow );
(r = new ActionReference()).putClass(stringIDToTypeID(currentTool));
(d = new ActionDescriptor()).putReference(stringIDToTypeID("target"), r);
d.putObject(stringIDToTypeID("to"), stringIDToTypeID("target"), tool);
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
};
};
////////////////////////////////////

 

Translate