Skip to main content
Flowgun
Inspiring
July 14, 2025
Answered

Script to Change Brush Blend Mode

  • July 14, 2025
  • 1 reply
  • 304 views

I came across this script that changes the Brush blend mode:

// Select the paint brush tool
var idslct = stringIDToTypeID( "select" );
var desc226 = new ActionDescriptor();
var idnull = stringIDToTypeID( "null" );
var ref170 = new ActionReference();
var idPbTl = stringIDToTypeID( "paintbrushTool" );
ref170.putClass( idPbTl );
desc226.putReference( idnull, ref170 );
executeAction( idslct, desc226, DialogModes.NO );

// blend mode
var desc = new ActionDescriptor();
var idset = stringIDToTypeID( "set" );
//alert(desc.getEnumerationValue(stringIDToTypeID("mode")));
desc.putEnumerated(stringIDToTypeID("mode"), stringIDToTypeID("blendModel"), stringIDToTypeID("clearEnum"));
desc226.putObject( stringIDToTypeID( "to" ), stringIDToTypeID( "null" ), desc);
executeAction( idset, desc226, DialogModes.NO );

 

It works fine, but it has one flaw: it resets the brush settings. For example, if my brush has "Scattering" turned on by default, and I turn it off, the script checks it back on. 

Is there a better way to change the brush blend mode? or maybe a way to first read the current brush settings, and re-applying them after changing the blend mode?

Correct answer jazz-y
setPaintbrushBlendMode('color');

function setPaintbrushBlendMode(mode) {
    var s2t = stringIDToTypeID;
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
    r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));
    if (executeActionGet(r).getEnumerationType(p) == s2t('paintbrushTool')) {
        var cto = executeActionGet(r).getObjectValue(s2t('currentToolOptions'));
        cto.putEnumerated(s2t('mode'), s2t('blendMode'), s2t(mode));
        (r = new ActionReference()).putClass(s2t('paintbrushTool'));
        (d1 = new ActionDescriptor()).putReference(s2t('target'), r);
        d1.putObject(s2t('to'), s2t('target'), cto);
        executeAction(s2t('set'), d1, DialogModes.NO);
    }
}

1 reply

creative explorer
Community Expert
Community Expert
July 15, 2025

@Flowgun The line desc226.putObject( stringIDToTypeID( "to" ), stringIDToTypeID( "null" ), desc); is attempting to set properties of the brush tool itself, and in doing so, it seems to be overriding the current brush's specific settings with a more generic configuration before applying the blend mode. 

m
Flowgun
FlowgunAuthor
Inspiring
July 15, 2025

yes, but what's the alternative? apparently the line always disables all settings except for shape dynamics and smoothing that would be turned on. I want to just change the blend mode.

For now, my working solution is to use autohotkey to read an array that has the blend mode names as keys, and their corresponding hotkeys as values, and it would just send the corresponding hotkey to change the blend mode.
I prefer a solution that uses photoshop scripting instead of sending keys.