Skip to main content
Participant
December 16, 2017
Answered

Getting the name of the current brush preset

  • December 16, 2017
  • 5 replies
  • 4615 views

I'm using Kyle T. Webster's brush packs and I'm trying to write a script that will grab the name of the selected brush preset.  The below code is the closest I've come, but it returns the wrong name:

var ref = new ActionReference();

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

var toolDesc  = executeActionGet(ref).getObjectValue((stringIDToTypeID('currentToolOptions')));

var brushDesc = toolDesc.getObjectValue(stringIDToTypeID('brush'));

var name      = brushDesc.getString(stringIDToTypeID('name'));

For instance, if I select "Kyle's Inbox - Fountania Soft", the above will output "ktw large pencil".  I'm assuming the latter is some kind of internal ID, but for the purpose of my script, I would like to have the user-visible preset label.  Does anyone know how I could achieve that?  Thank you!

This topic has been closed for replies.
Correct answer Kukurykus

Name it as Brush Presets Notifier.jsx and copy to your Photoshop Startup Scripts folder, so probably at end of this path:

C:\Program Files (x86)\Common Files\Adobe\Startup Scripts CS6\Adobe Photoshop / (it's CS6 EXTENDED in my case)

if (typeof name != 'undefined') {

     if ((!eval(evl = "typeof arguments != 'undefined'") && notifiersEnabled)

     || (eval(evl) && (args = arguments)[1] != 1936483188)) notifiersEnabled = false

     if (sTT = function(v) {return stringIDToTypeID(v)}, !notifiersEnabled) {

          for(notifiersEnabled = true, i = 0; i < notifiers.length; i++) {

               if (slct = app.notifiers.event == 'slct') break

          }

          if (typeof slct == 'undefined') notifiers.add('slct',  File($.fileName))

     }

     else if((args[0].getReference(sTT('null')).getDesiredClass()) == sTT('brush')) {

          function rw(v1, v2, v3) {v2.open(v1), v1 < 'w' ? v3 = v2.read() : v2.write(v3), v2.close(); return v3}

          alert(rw('r', File('~/desktop/ScriptingListenerJS.log')).match(/"(.*)\b(.*\n){4}$/)[1])

     }

}

(Re)open your Photoshop, click any Brush Preset and you get alert with its name, click any others to see that really works...

5 replies

Participant
June 26, 2021

In the current version of photoshop if you drag you mouse over the current brush preset without clicking on it and then wait, the name of the brush should show up. It doesn't work if you're directing your mouse using a drawing tablet (at least in my case) and you have to use the trackpad.

Inspiring
January 20, 2018

that explains it

Inspiring
January 20, 2018

Hi r-bin,

great script! It will be useful.

But the same old Adobe problem exists:

1. select a tool preset

2. change the size of the brush

3. now run the script - it doesn't work.

This is an Adobe problem that I mentioned years ago:

When you select a tool preset from the tool presets panel, it 'highlights' in blue (or whatever color your operating system uses when you make a selection). This is so you can keep track of what tool preset you're on.

But when you change the brush size, the 'highlight' disappears. And now we don't know what preset we're on anymore. Also, your script doesn't work either.

*Edit- I'm still using CC2014. Have they fixed this in newer versions?

Kukurykus
Legend
January 20, 2018

That probably has to be bug of versions beyond CS6 Extended, as I just tried to change brush size from 3 possible locations (Brush Preset panel, Brush panel and Options pane) and blue highligting didn't dissaper quite contrary to author of a topic!

Inspiring
January 20, 2018

what version are you using?

Legend
December 18, 2017

It works, but use at your own risk, because it's done "through the ass". )

P.S. Sorry for my english )

alert( get_selected_preset_name() )

function get_selected_preset_name()

    {

    try

        {

        var file = new File(Folder.temp.fsName + "\\" + "tmp.tpl");

        save_preset();

        var list1 = get_preset_list();

        if (!list1) { file.remove(); return null; };

        if (!del_target_preset()) { file.remove(); alert("No selected preset"); return null; };

        var list2 = get_preset_list();

        load_preset();

        file.remove();

        if (!list2) { return null; };

        for (var i in list2 )

            for (var n in list1 )

                {

                if (list1 == list2)

                    {  

                    delete list1;

                    break;

                    }

                }

        var name = "";

        for (var i in list1 )

            {

            if (list1 != undefined)

                {

                name = list1

                select_preset(list1);

                break;

                }

            }

        return name;

        function save_preset()

            {

            try

                {

                var r = new ActionReference();

                r.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "toolPreset" ) );

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

       

                var d = new ActionDescriptor();

                d.putPath( charIDToTypeID( "null" ), new File(Folder.temp.fsName + "\\" + "tmp.tpl") );

                d.putReference( charIDToTypeID( "T   " ), r );

       

                executeAction( charIDToTypeID( "setd" ), d, DialogModes.NO );

       

                return true;

                }

            catch(e) { return false; }

            }

       

        function load_preset()

            {

            try

                {

                var r = new ActionReference();

                r.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "toolPreset" ) );

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

       

                var d = new ActionDescriptor();

                d.putReference( charIDToTypeID( "null" ), r );

                d.putPath( charIDToTypeID( "T   " ), new File(Folder.temp.fsName + "\\" + "tmp.tpl") );

       

                executeAction( charIDToTypeID( "setd" ), d, DialogModes.NO );

       

                return true;

                }

            catch(e) { return false; }

            }

       

        function select_preset(name)

            {

            try {

                var d = new ActionDescriptor();

                var r = new ActionReference();

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

                d.putReference( charIDToTypeID( "null" ), r );

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

                return true;

                }

            catch(e) { return false; }

            }

       

        function del_target_preset()

            {

            try

                {

                var r = new ActionReference();

                r.putEnumerated( stringIDToTypeID( "toolPreset" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );

       

                var d = new ActionDescriptor();

                d.putReference( charIDToTypeID( "null" ), r );

       

                executeAction( charIDToTypeID( "Dlt " ), d, DialogModes.NO );

       

                return true;

                }

            catch(e) { return false; }

            }

       

        function get_preset_list()

            {

            try

                {

                var r = new ActionReference();

                r.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "presetManager" ) );

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

       

                var ret = executeActionGet(r).getList(stringIDToTypeID("presetManager"))

       

                var ok = false;

                   

                for (var i = 0; i < ret.count; i++)

                    {

                    if (ret.getObjectType(i) == stringIDToTypeID( "toolPreset" ))

                        {

                        ok = true;  

                        ret = ret.getObjectValue(i).getList(stringIDToTypeID("name"));

                        break;

                        }

                    }

       

                if (!ok) { alert("Damn!"); return null; }

       

                var list = new Array();

       

                for (var i = 0; i < ret.count; i++) list.push(ret.getString(i));

               

                return list;

                }

            catch(e) { alert(e); return null; }

            }

        }

    catch(e) { alert(e);  }

    }

Kukurykus
Legend
December 18, 2017

Maybe I'm wrong. You did certainly good job, but didn't he mean to get name of current 'Brush Preset" instead of 'Tool Preset', what your script does?

Legend
December 18, 2017

Oops! I think I screwed up. It is necessary to remake.

Kukurykus
KukurykusCorrect answer
Legend
December 17, 2017

Name it as Brush Presets Notifier.jsx and copy to your Photoshop Startup Scripts folder, so probably at end of this path:

C:\Program Files (x86)\Common Files\Adobe\Startup Scripts CS6\Adobe Photoshop / (it's CS6 EXTENDED in my case)

if (typeof name != 'undefined') {

     if ((!eval(evl = "typeof arguments != 'undefined'") && notifiersEnabled)

     || (eval(evl) && (args = arguments)[1] != 1936483188)) notifiersEnabled = false

     if (sTT = function(v) {return stringIDToTypeID(v)}, !notifiersEnabled) {

          for(notifiersEnabled = true, i = 0; i < notifiers.length; i++) {

               if (slct = app.notifiers.event == 'slct') break

          }

          if (typeof slct == 'undefined') notifiers.add('slct',  File($.fileName))

     }

     else if((args[0].getReference(sTT('null')).getDesiredClass()) == sTT('brush')) {

          function rw(v1, v2, v3) {v2.open(v1), v1 < 'w' ? v3 = v2.read() : v2.write(v3), v2.close(); return v3}

          alert(rw('r', File('~/desktop/ScriptingListenerJS.log')).match(/"(.*)\b(.*\n){4}$/)[1])

     }

}

(Re)open your Photoshop, click any Brush Preset and you get alert with its name, click any others to see that really works...