Skip to main content
Inspiring
June 28, 2015
Question

History Brush Blending Mode

  • June 28, 2015
  • 5 replies
  • 1742 views

I remember some time ago following a thread on PS-Scripts.com about not been able to access and change the blending mode of the history brush through a script.

Unfortunately, PS-Scripts.com is no longer online and I was wondering if things have changed with regards to changing the History Brush blending mode through a script.

This topic has been closed for replies.

5 replies

Pedro Cortez Marques
Legend
November 11, 2015

Give a look to this.

Is it possible to script brush opacity?

I think you can use this with any brush kind tool. Just create a preset tool (they contain: all brush vars + all tool properties)

// first, prepare your historybrush tool and use this to save its preset name (or save it directly on the tool properties);

save_preset("AAAA");

// then, use this wherever you want to get the preset (including belending mode)

app.currentTool = "historyBrushTool"; // select historybrush

select_preset("AAAA");

// function to create the preset tool

function save_preset(name) {

    try {

        var desc21 = new ActionDescriptor();

        var ref18 = new ActionReference();

        ref18.putClass( stringIDToTypeID( "toolPreset" ) );

        desc21.putReference( charIDToTypeID( "null" ), ref18 );

        var ref19 = new ActionReference();

        ref19.putProperty( charIDToTypeID( "Prpr" ), charIDToTypeID( "CrnT" ) );

        ref19.putEnumerated( charIDToTypeID( "capp" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );

        desc21.putReference( charIDToTypeID( "Usng" ), ref19 );

        desc21.putString( charIDToTypeID( "Nm  " ), name );

        executeAction( charIDToTypeID( "Mk  " ), desc21, DialogModes.NO );

    } catch(e) { }

}

// function to select the preset tool

function select_preset(name) {

    try {

        var desc = new ActionDescriptor();

        var ref = new ActionReference();

        ref.putName( stringIDToTypeID( "toolPreset" ), name );

        desc.putReference( charIDToTypeID( "null" ), ref );

        executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );

        ref = null;

        desc = null;

    } catch(e) { }

}

Inspiring
November 9, 2015

I'm having a similar issue – I would like to switch the blend mode of a brush from Normal to Clear.  I know that the shortcuts do that, but my goal is to be able to record the action and since this event is not recordable… here I am asking for help.

It would be grate to find a solution or a work around.

I've tried:

1. Script listener - doesn't work, no event is captured

2. Actions - do not record

3. and I looked through the reference guide for photoshop JS scripting for sample code that I could rework (I'm no programmer)

4. Of course Google search but nothing there

The closest thing I found was this: toggle brush mode 'Behind' on/off with keyboard shortcut? But the scrip is no longer available…

I was thinking of an alternative… if there's a ways to write a script that executes the keyboard shortcut that may do the trick, but I've not fount any way of doing that with code.

Any help would be greatly appreciated.

Cheers,

C

JJMack
Community Expert
Community Expert
November 9, 2015

I do not know if this will work or not.  It may.  If you want a script that toggles between two states you need to have a way to know the current state  and if the is not possible to pick a state set that state and set some state indicator that you can test to know the current state.  With a Photoshop scriptt it is possible to set a custom option or record the current state some how.

If you have the state indicator you also need to be able to switch states.  As you have found some thing are not  recorded. The scriptlistener does nothing when something can not be recorded. There may also be no DOM interface to switch the state or a standard menu item to switch states.

So what can one try?  Often over look is the ability to set some none standard things. What do I mean?  Before I get to that. There is a problem with what you want to do.  For what you want to do in not possible in Photoshop.  While there is a normal blend mode there is no "Clear" blend mode. You would need to write a Plug-in to implement a new feature for Photoshop.    However I believe it would be possible to toggle between to blending mode that are possible.  Often overlook are Presets.   Preset you define/create can be use in Photoshop automation.  The Automation will fail it these name preset have not been added to you Photoshop presets.   You will see that selecting a preset will record in Actions and be recorded by the Scriptlistener.  So you can create a two history brush presets.  "Normal" and "Clear" and use these in your script.  "Clear" would need to set some valid blending mode.

JJMack
Inspiring
November 11, 2015

Had a quick look and it seems that you can do it with AppleScript.

From what I have seen it will be something on the lines of:-

Normal Blendmode

tell application "Adobe Photoshop CC 2015"

tell application "System Events" to keystroke "n" using {shift down, option down}

end tell

Clear Blendmode

tell application "Adobe Photoshop CC 2015"

tell application "System Events" to keystroke "r" using {shift down, option down}

end tell

It should give you a starting point.

The AppleScripts might require tweaking to get them to work as I don't have a Mac.


Thanks for all your replays!

I think I should've started a new thread, as the issue I'm having is more about the brush blending modes and recording the strokes for playback.

GOAL: record my brush strokes while illustrating and play them back so that can be screen captured

ISSUE: switching brush blending mode is not being captured when recording via actions

Here's an update on my status. SuperMerlin's suggestion is what came closest to my end goal.

I've tried that approach and got it to work but I ran into a couple of problems:

1. When the jsx calls the .app file (.exe on window) the screen flickers as the app executes the code.  When capturing the screen at playback time that will cause a problem not to mention the eye fatigue while working.  I remember (I think) there's some jsx code that freezes the screen until the script has fished running, but I couldn't find any reference on that or if there is a way to run the app in the background… either would solve that problem, which I would really like to achieve. 

2. The execution of the script is recorded by the action panel but the blending mode does not change at playback. This is infuriating!

Here's the working code up to date:

In AppleScript then save it as an .app (Brush_Mode_Normal.app)

tellapplication "Adobe Photoshop CC 2015" toactivate

tell application "System Events"

  tell process "Photoshop"

  keystroke "n" using {shift down, option down}

  end tell

endtell

In AppleScript then save it as an .app (Brush_Mode_Clear.app)

tellapplication "Adobe Photoshop CC 2015" toactivate

tell application "System Events"

  tell process "Photoshop"

  keystroke "r" using {shift down, option down}

  end tell

endtell

Put those two files in /Applications/Adobe Photoshop CC 2015/Presets/Scripts/Apple_Scripts
(I've created a separate folder for the Apple Scripts) but you can put them anywhere you want as long as the directory in the the jsx file matches upPresets/ScriptsPresets/Scripts

The code works as a switcher between any brush and it's inverse (erases).  All you need to remember is one key combination allocated to the JSX script rather then the 3 keys per blending mode.

And this is the updated code from SuperMerlin that switches between the two states

#target photoshop; 

app.bringToFront(); 

 

 

var SCRIPTS_FOLDER =  decodeURI(app.path + '/' + localize("$$$/ScriptingSupport/InstalledScripts=Presets/Scripts")); 

var Normal = new File(SCRIPTS_FOLDER + "/Apple_Scripts/Brush_Mode_Normal.app"); 

var Clear = new File(SCRIPTS_FOLDER + "/Apple_Scripts/Brush_Mode_Clear.app"); 

 

 

switch($.getenv("BrushMode")){ 

    case null : $.setenv("BrushMode","Clear"); Clear.execute(); break; 

    case "Normal" : $.setenv("BrushMode","Clear"); Clear.execute(); break; 

    case "Clear" : $.setenv("BrushMode","Normal"); Normal.execute(); break; 

}

c.pfaffenbichler
Community Expert
Community Expert
June 29, 2015

In post 11 xbytor provides a link to an archived version of ps-scripts.com:

PS-Scripts.com temporarily suspended?

JJMack
Community Expert
Community Expert
June 29, 2015

I think if you set a tool preset for the history brush with the blending mode you want.  You could use scriptlistener action manager code to select the preset by preset name. The would select the history brush tool with the settings you want.

There are few Photoshop scripting resources on the web. Only a few Photoshop Books will cover Photoshop in any depth.

Adobe has some documentation on the web over years I have downloaded some of their documents.

JJMack
StrongBeaver
Legend
June 29, 2015

The site just abruptly ceased to exist. Thanks for the heads up ian. 

IanBarberAuthor
Inspiring
June 29, 2015

I have just read elsewhere that unfortunately, the owner of the site Mr Mike Hale passed away which is why I am guessing the site has been taken down.
although I never met or spoke to Mike, I found some of the information, code snippets and help on his site to be excellent.

Ian

StrongBeaver
Legend
June 29, 2015

Ps-Scripts.com is dead, did this happen recently, can anyone verify ? If so the only source for scripting in Photoshop is the Adobe communities.