Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Getting the name of the current brush preset

New Here ,
Dec 16, 2017 Dec 16, 2017

Copy link to clipboard

Copied

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!

TOPICS
Actions and scripting

Views

2.1K

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Dec 16, 2017 Dec 16, 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)...

Likes

Translate

Translate
Adobe Community Professional ,
Dec 16, 2017 Dec 16, 2017

Copy link to clipboard

Copied

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...

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 18, 2017 Dec 18, 2017

Copy link to clipboard

Copied

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);  }

    }

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 18, 2017 Dec 18, 2017

Copy link to clipboard

Copied

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?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 18, 2017 Dec 18, 2017

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 18, 2017 Dec 18, 2017

Copy link to clipboard

Copied

Anyway if you're going to write new version don't delete this one, it may be really useful, even only for learning puropses

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Dec 18, 2017 Dec 18, 2017

Copy link to clipboard

Copied

Also your  function load_preset()  and function save_preset() are the same.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 18, 2017 Dec 18, 2017

Copy link to clipboard

Copied

SuperMerlin 

Also your  function load_preset()  and function save_preset() are the same.

They are different. Would you check how it works?
I do not have time now to remake the model on BrushPresets, but I think it's possible. Who wants to - can try it.)

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 27, 2019 Feb 27, 2019

Copy link to clipboard

Copied

hi r-bin,

i try to  rplace "toolPreset" with "brush" ,but get empty.Where is wrong?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 27, 2019 Feb 27, 2019

Copy link to clipboard

Copied

Deleting the current brush will not work on CS6. And accordingly the script does not work.

On  CC2018 it will be if the selection of the brush is visible in the brushes panel.

In short, it's all nonsense.)

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 27, 2019 Feb 27, 2019

Copy link to clipboard

Copied

i had using it in cc2019,  the data using get_preset_list()  is same Before and after the del_target_preset()。 so It's always  the list1=list2 then alert empty

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 20, 2018 Jan 20, 2018

Copy link to clipboard

Copied

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?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jan 20, 2018 Jan 20, 2018

Copy link to clipboard

Copied

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!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 20, 2018 Jan 20, 2018

Copy link to clipboard

Copied

what version are you using?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jan 20, 2018 Jan 20, 2018

Copy link to clipboard

Copied

13.0.1 x64 with Windows 10

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jan 22, 2018 Jan 22, 2018

Copy link to clipboard

Copied

boo radley 2013

I still do not know how to solve the problem. In different versions, everything works differently, but still does not give you the desired result. Perhaps it will be easier to write your own panel with which to select the desired brush and then we will know exactly what is selected. But I do not want to do it.(

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 09, 2018 Feb 09, 2018

Copy link to clipboard

Copied

Okey people, I solved problem of unselected preset brush in Ps CC version where you say Adobe produced another bug

If you want to use it just go to Edit / Preferences / General and fill "History Log" box, tick "Save Log Items To Metadata" radio button, and select "Detailed" from "Edit Log Items" dropdown list. Now each time you select brush preset and run this script it will alert you last one used, even if you already unselected that from Brush Presets List (funny is that I don't have CC! )

if (documents.length && (prf = preferences).useHistoryLog

     && prf.saveLogItems == SaveLogItemsType.METADATA

     && prf.editLogItems == EditLogItemsType.DETAILED) {

     (function(){

          with(p = new PhotoshopSaveOptions()) {

               annotations = alphaChannels = layers

               = embedColorProfile = spotColors = 0

          }

          activeDocument.saveAs(f = File('~/desktop/.psd'), p, 1)

          f.encoding = 'binary', f.open('r'), c = f.read().toSource()

          r = / brush \\u00E2\\u0080\\u009.{0,50}(?=\\u00E2)/g

          f.close(); if (cBrush = c.match(r)) {b = cBrush[cBrush.length -1]

          alert('Current Brush Preset: ' + b.slice(25))} f.remove()

     })()

}

It may not working in non-english versions, as metadata stores user language names. But maybe it needs other regexp then.

Here's a link to other source where someone found it's usable: How to Get current toolPreset name jsx - PS-SCRIPTS.COM

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jan 20, 2018 Jan 20, 2018

Copy link to clipboard

Copied

that explains it

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 26, 2021 Jun 26, 2021

Copy link to clipboard

Copied

LATEST

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines