Delete Tool Preset by Name

Photoshop Script Snippets - Note: Full Scripts go in the Photoshop Scripts Forum

Moderators: Tom, Kukurykus

weipai

Delete Tool Preset by Name

Post by weipai »

Here's a function that will delete a tool preset by name and do so without selecting the preset.
Code: Select all//usage:
//deleteToolPreset("Air Brush");

function deleteToolPreset(name){
    var ref = new ActionReference();
    ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
    var appDesc = executeActionGet(ref);

    var pmList = appDesc.getList(stringIDToTypeID("presetManager"));
    var nameList = pmList.getObjectValue(7).getList(charIDToTypeID('Nm  '));

    for (var index = 0; index < nameList.count; index++){
        if (nameList.getString(index) == name){
            index++;
            var idDlt = charIDToTypeID( "Dlt " );
            var desc2 = new ActionDescriptor();
            var idnull = charIDToTypeID( "null" );
            var list1 = new ActionList();
            var ref2 = new ActionReference();
            var idtoolPreset = stringIDToTypeID( "toolPreset" );
            ref2.putIndex( idtoolPreset, index );
            list1.putReference( ref2 );
            desc2.putList( idnull, list1 );
            executeAction( idDlt, desc2, DialogModes.NO );
            break;
            }
        else {}
        }
    }
teslaball
Posts: 7
Joined: Wed Jan 25, 2017 2:32 pm

Re: Delete Tool Preset by Name

Post by teslaball »

Hello,
I have tried to implement the code in hostscript.jsx and still does not work. And does getObjectValue(7) is a preset numbered 7th in order, and what if it is 10th, will it still be deleted?
Please help me on this because I am lost.
By the way I know it is old post, but it's worth to be here, especially if someone answers my question.
Thanks
User avatar
txuku
Posts: 136
Joined: Thu Jan 01, 1970 12:00 am

Re: Delete Tool Preset by Name

Post by txuku »

Bonjour

You create a new predefined form and copy its name
You paste this name into the script
Line 2

Code: Select all

DeleteToolPreset ("Brush tool test0 2") // "test0") // "Air Brush");

And an alert line 14

Code: Select all

alert (index)
That works well !
teslaball
Posts: 7
Joined: Wed Jan 25, 2017 2:32 pm

Re: Delete Tool Preset by Name

Post by teslaball »

Hi txuku,
Thanks for your answer, is this what you mean?
P.S. I placed dashes in the code where I made changes according to your answer so you can easily find them:

Code: Select all

//usage:
deleteToolPreset("MyBrush"); ------

function deleteToolPreset(name){
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var appDesc = executeActionGet(ref);

var pmList = appDesc.getList(stringIDToTypeID("presetManager"));
var nameList = pmList.getObjectValue(7).getList(charIDToTypeID('Nm '));

for (var index = 0; index < nameList.count; index++){
if (nameList.getString(index) == name){
alert(index); ----------
var idDlt = charIDToTypeID( "Dlt " );
var desc2 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var list1 = new ActionList();
var ref2 = new ActionReference();
var idtoolPreset = stringIDToTypeID( "toolPreset" );
ref2.putIndex( idtoolPreset, index );
list1.putReference( ref2 );
desc2.putList( idnull, list1 );
executeAction( idDlt, desc2, DialogModes.NO );
break;
}
else {}
}
}
User avatar
txuku
Posts: 136
Joined: Thu Jan 01, 1970 12:00 am

Re: Delete Tool Preset by Name

Post by txuku »

Bonjour

I remove the new forms I have created by means of this function !

Is not that your case? :)
teslaball
Posts: 7
Joined: Wed Jan 25, 2017 2:32 pm

Re: Delete Tool Preset by Name

Post by teslaball »

txuku wrote:Bonjour

I remove the new forms I have created by means of this function !

Is not that your case? :)
Hi txuku,
I am totally lost now, please if you feel like editing the above code so I can understand exactly what you mean.
Thank you
User avatar
txuku
Posts: 136
Joined: Thu Jan 01, 1970 12:00 am

Re: Delete Tool Preset by Name

Post by txuku »

Bonjour

What is the name of the new forms you create in English ?
teslaball
Posts: 7
Joined: Wed Jan 25, 2017 2:32 pm

Re: Delete Tool Preset by Name

Post by teslaball »

Hi,
I actually messed something up in main.js and corrected the problem, actually the solution is to uncomment line 2 and everything is working fine now. Thanks again txuku, you helped me alot as I really understand now what you wanted to tell me all the time. My apollogies.
User avatar
txuku
Posts: 136
Joined: Thu Jan 01, 1970 12:00 am

Re: Delete Tool Preset by Name

Post by txuku »

:D