• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Photoshop tool preset list, by current/active tool?

New Here ,
Mar 16, 2016 Mar 16, 2016

Copy link to clipboard

Copied

0down votefavorite

Ok so I know that this has been asked before but In a more general way(recently). I'm trying to get the list of toolpresets but only those of the active tool selected. So If I have the Brush tool selected, It would only scan/output for just the brush tool. I know you can do the tool presets list as a whole(see script below), but I'm trying to run a make new tool preset option(not the default) that you input the tool preset name you want, It scans the current active tool presets to see if that name exists, if it does already exist it error messages and restarts the input process again, halting. I can get it to check the whole list and work fine, but I'd like ONLY to check by active tool selected, so it only checks those of that type vs the entire list. By default photoshop already does it, it only checks the list of the tool you are using, i'm trying to do the same. Other wise as it stands now if there is a name for example in the eraser tool presets, and i try inputting that name as a regular brush tool preset, it finds the name and says i cannot process because the name already exists(in erasers), that's why Im asking. I hope this makes sense. What i started with was this script on the forums:

function getToolPresetNames() {
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var appDesc = executeActionGet(ref); var List = appDesc.getList(stringIDToTypeID('presetManager'));
var presetNames=[];
var list = List.getObjectValue(7).getList(charIDToTypeID('Nm '));
for (var i = 0; i < list.count; i++) {
var str = list.getString(i);
presetNames
.push(str); } r
eturn
presetNames;

}

TOPICS
Actions and scripting

Views

3.7K

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 Expert ,
Mar 16, 2016 Mar 16, 2016

Copy link to clipboard

Copied

Here are the problems I see.  The check box in the preset pull-down dialog window on the bottom left  "Current Tool Only" effect the which "Tools presets"  a script can select.  When its state in uncheck any current Photoshop preset can be selected by a script. If the "preset" was not for the current tool the preset's tool will also be selected and become the current active tool. However if the "check box" state is checked only presets for the current tool can be selected.  So if you try to select a preset by name and it fails you do not know if the "Named Preset" exists or not because you don't know the state of the "check box" or what the current active Photoshop tool is. 

You can only select some Photoshop tools to activate the with a script the one that select tool name recorded in actions via action manager code.  Hpwever. when the state of the checkbox is not check you can select any tool preset to activate the tool and set the toop settings. If the prest fails to select you can load a preset for the tool and select it when the checkbox is not checked.  However, you do not know the state  of the "check box Current Tool Only"  nor can you set its state with a script.

The best I have been able to do is to inform the user with an alert to uncheck the check box "Current Tool Only"

Select Tool Preset script

// Note:  This script only works if the correct tool for the preset is currently selected.

//            Or "Current Tool Only" is not checked in Photoshop's  "Tool Options Bar" Presets pull-down list dialog at the bottom left. 

var ToolPresetName = "JJMack soft oval red brush" ; // The Photoshop Tool preset name that you created and saved into a set  

var ToolPresetSet  = "JJMackToolsPresetsSet";        // The SetName.tpl file need to be same folder as this Photoshop script.

try {SelectToolPreset(ToolPresetName);}

catch(e) {

  if (LoadToolPresetSet(ToolPresetSet)) {

  try {SelectToolPreset(ToolPresetName);}

  catch(e) {alert('Was unable to Select the Tools Preset "' + ToolPresetName + '".\nUncheck Preset pulld-down dialog "Current Tool Only" check box');}

  }

  else {alert("Was unable to load Tools Presets Set " + ToolPresetSet);}

}

// =================================================== Helper functions ===================================================== //

function SelectToolPreset(PresetName) {

  // === Select Preset, tool must be selected or 'show current tool only' unchecked  ===

  var desc = new ActionDescriptor();

  var ref = new ActionReference();

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

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

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

}

function LoadToolPresetSet(SetName) {

  returncode = true;

  var scriptLocation = String(findScript());

  var path = scriptLocation.substr(0, scriptLocation.lastIndexOf("/") + 1 ) ;

  var SetFile = new File(path + SetName + ".tpl");   // Requited to be in the script's folder

  if (!SetFile.exists) { returncode = false; }

  else {

  try {LoadToolsSet(SetFile);}

  catch(e) { returncode = false; }

  }

  return returncode ;

}

function LoadToolsSet(tplFile) {

  // ========load a set of Tools Presets=========================

  var desc = new ActionDescriptor();

  var ref = new ActionReference();

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

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

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

  desc.putPath( charIDToTypeID( "T   " ), new File( tplFile ) );

  desc.putBoolean( charIDToTypeID( "Appe" ), true );

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

}

// Find the location where this script resides

function findScript() {

  var where = "";

  try { FORCEERROR = FORCERRROR;}

  catch(err) { where = File(err.fileName);}

  return where ;

}

JJMack

Votes

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
Community Expert ,
Mar 16, 2016 Mar 16, 2016

Copy link to clipboard

Copied

You may want to look at X's script PresetLister it list presets by  tool name.  The script is in his xTools package. PresetLister.js  I do not know how to find out what Photoshop tool is currently selected in the tools palette or if the edit toolbar icon is highlighted.

JJMack

Votes

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 ,
Mar 16, 2016 Mar 16, 2016

Copy link to clipboard

Copied

Thanks JJMack, from what you have posted and more research It seems like it is most likely impossible to list tool presets by tool type. Seems like these are the only possible choices(from X presetlistener seen below).  So can can get all the toolpresets currently loaded into the manager, but not differentiate what entry belongs to what tool e.g.: brush/eraser/smudge/etc. Hmm i figured there would be a way...

  self.brushes       = []; self.colors        = []; self.gradients     = []; self.styles        = []; self.patterns      = []; self.shapingCurves = []; self.customShapes  = []; self.toolPresets   = [];

Votes

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
Community Expert ,
Mar 16, 2016 Mar 16, 2016

Copy link to clipboard

Copied

anonymousasyou wrote:

Thanks JJMack, from what you have posted and more research It seems like it is most likely impossible to list tool presets by tool type. Seems like these are the only possible choices(from X presetlistener seen below).  So can can get all the toolpresets currently loaded into the manager, but not differentiate what entry belongs to what tool e.g.: brush/eraser/smudge/etc. Hmm i figured there would be a way...

The Preset Manager handles many presets beside "ToolPresets".  All can be listed. Some of the Presets you seem to be interested in are not "toolptesets" but are presets Photoshop tools can use like custom Brush, Shapes. Colors, Gradients  etc like you list above.  I posted  you may want to look at X's script PresetLister.js. in his xTools package. It seems to do what you want. 

Capture.jpg

JJMack

Votes

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
Contributor ,
Dec 13, 2018 Dec 13, 2018

Copy link to clipboard

Copied

has anyone found a solution to this by any chance?

If "Current Tool Only" box is checked, then is it possible to get a list of the tool presets for the active tool only (example, all tool presets for the eraser tool only?)

Votes

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
Community Expert ,
Dec 14, 2018 Dec 14, 2018

Copy link to clipboard

Copied

A script the get all Preset manager objects like X's presetslister seem to be able to get all types of presets names.  So I would think X could get as which Tool preset name is for what tool. That information need to be in the tool preset object along with all the too'ls setting for the tool preset name.   I would imagine someone that know how to use Action manager code could get tool name You can show that tool in the Preset list.

Capture.jpg

JJMack

Votes

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 14, 2018 Dec 14, 2018

Copy link to clipboard

Copied

Votes

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
Contributor ,
Dec 14, 2018 Dec 14, 2018

Copy link to clipboard

Copied

the following code by r-bin will get a list of all tool presets, but still not a list only of the current tool - unless I am doing something wrong.

1. I make sure "Current Tool Only" box is checked

2. I select the eraser tool

3. I run this script, and it gives a list of ALL tool presets, not just for the eraser tool

Am I doing something wrong?

alert(getToolPresetNames().join("\n"));   

   

function getToolPresetNames() {     

    var ref = new ActionReference();     

    ref.putProperty(stringIDToTypeID("property"),

stringIDToTypeID("presetManager"));   

    ref.putEnumerated(charIDToTypeID("capp"),

charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));     

    var appDesc = executeActionGet(ref);     

    var List = appDesc.getList(stringIDToTypeID

("presetManager"));     

    var presetNames = [];     

    var list = List.getObjectValue(7).getList

(charIDToTypeID("Nm  "));     

    var list2 = List.getObjectValue(7).getList

(stringIDToTypeID("class"));      

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

        var str = list.getString(i);     

        var str2 = typeIDToStringID(list2.getClass(i));     

        presetNames.push([str,str2]);     

    }     

    return presetNames;     

};  

Votes

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
Community Expert ,
Dec 14, 2018 Dec 14, 2018

Copy link to clipboard

Copied

That script seem to be like Xtools presetlister but just return tool presets not the all the other Preset the Preset manager manages.  I still believe that the tool for each preset is for can be retried with action manager code if one know how code it for  Adobe internal objects.  The Preset manager can show the Tool Icon for each tool Preset and Photoshop can list current tool only presets. So For sure Photoshop has that information.

Filter the str2 tool

alert(getToolPresetNames("paintbrushTool").join("\n"));   

   

function getToolPresetNames(tool) {     

    var ref = new ActionReference();     

    ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("presetManager"));   

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

    var appDesc = executeActionGet(ref);     

    var List = appDesc.getList(stringIDToTypeID("presetManager"));     

    var presetNames = [];     

    var list = List.getObjectValue(7).getList(charIDToTypeID("Nm  "));     

    var list2 = List.getObjectValue(7).getList(stringIDToTypeID("class"));      

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

        var str = list.getString(i);     

        var str2 = typeIDToStringID(list2.getClass(i));     

       // presetNames.push([str,str2]);     

        if (str2==tool) presetNames.push([str,]);        

    }     

    return presetNames;     

};    

JJMack

Votes

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
Community Expert ,
Dec 15, 2018 Dec 15, 2018

Copy link to clipboard

Copied

current tool

alert(getToolPresetNames(currentToolName()).join("\n"));   

   

function getToolPresetNames(tool) {     

    var ref = new ActionReference();     

    ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("presetManager"));   

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

    var appDesc = executeActionGet(ref);     

    var List = appDesc.getList(stringIDToTypeID("presetManager"));     

    var presetNames = [];     

    var list = List.getObjectValue(7).getList(charIDToTypeID("Nm  "));     

    var list2 = List.getObjectValue(7).getList(stringIDToTypeID("class"));      

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

        var str = list.getString(i);     

        var str2 = typeIDToStringID(list2.getClass(i));     

       // presetNames.push([str,str2]);     

        if (str2==tool) presetNames.push([str,]);        

    }     

    return presetNames;     

};

function currentToolName() {

var ref = new ActionReference();

ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("tool"));

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

var applicationDesc = executeActionGet(ref);

//alert(typeIDToStringID(applicationDesc.getEnumerationType(stringIDToTypeID("tool"))));

return(typeIDToStringID(applicationDesc.getEnumerationType(stringIDToTypeID("tool"))));

}    

JJMack

Votes

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
Contributor ,
Dec 15, 2018 Dec 15, 2018

Copy link to clipboard

Copied

thanks guys, these work!!!

JJMack - it works!!! Finally, a solution It works PERFECTLY

I have a question - how can this script work on CC2014? I am still using that version, is there a way to do so?

alert(getToolPresetNames(currentToolName()).join("\n"));  

  

function getToolPresetNames(tool) {    

    var ref = new ActionReference();    

    ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("presetManager"));  

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

    var appDesc = executeActionGet(ref);    

    var List = appDesc.getList(stringIDToTypeID("presetManager"));    

    var presetNames = [];    

    var list = List.getObjectValue(7).getList(charIDToTypeID("Nm  "));    

    var list2 = List.getObjectValue(7).getList(stringIDToTypeID("class"));     

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

        var str = list.getString(i);    

        var str2 = typeIDToStringID(list2.getClass(i));    

       // presetNames.push([str,str2]);    

        if (str2==tool) presetNames.push([str,]);       

    }    

    return presetNames;    

};

function currentToolName() {

var ref = new ActionReference();

ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("tool"));

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

var applicationDesc = executeActionGet(ref);

//alert(typeIDToStringID(applicationDesc.getEnumerationType(stringIDToTypeID("tool"))));

return(typeIDToStringID(applicationDesc.getEnumerationType(stringIDToTypeID("tool"))));

}   

Votes

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
Community Expert ,
Dec 15, 2018 Dec 15, 2018

Copy link to clipboard

Copied

I only hack at scripting.  I do not know  JavaScript or how to code Action manager code to retrieve information.  Scriptlistener records   executeAction steps.  Which easy to tune into JavaScript functions.  The  executeActionGet ref code I need to steal from r-bin and SuperMerlin  since Paul left and Mike passed.

I can read some JavaScript code see what is going on and may be able to modify it somewhat to do what I want to do.

Adobe make changes to Photoshop's ScriptigSupport plug-in from in some versions of Photoshop. So some version of Photoshop have bugs that may be fixed in newer Photoshop versions.  A newer versions may have new bugs so things that use to work  to no longer work. Many version have reported bugs that Adobe has acknowledged are bugs that Adobe does not care to fix.

Some newer Photoshop  feature may cause failures in some Photoshop Script errors in some Photoshop version for Adobe failed to update scripting support to handle a new feature or preferences. Some version of Photoshop scripting have support older versions do not have.

I do not know exactly what is or what is not supported in the different versions of Photoshop scripting or where all the bugs are.  I know I have had to add code to some of by scripts to program around Adobe Bugs in different version of Photoshop.  Old working scripts may fail in the next new Photoshop version.  In some script I had to check which version of Photoshop is running to see if if the scripting support need for the script will be available and exit with a message if  some needed function is not supported in the running Photoshop version.

There are issues in Photoshop scripting some you can program around.

Adobe replaced Photoshop's Scripting ScriptUI module with a new implementation that is not fully compatible with the old ScriptUI implementation so some old Photoshop scripts  dialog are no longer functional.

Adobe Development does not seem to do much regression testing from what I have seem.  Photoshop's quality is one a down hill path for its bugs population is expanding.

JJMack

Votes

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
Contributor ,
Dec 15, 2018 Dec 15, 2018

Copy link to clipboard

Copied

well I must thank you and SuperMerlin for making this work. I can see that other users have been looking for a solution to this for many years now. Finally, you have discovered it

I must ask however, can your script be modified to work in CC2014?

Votes

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
Community Expert ,
Dec 16, 2018 Dec 16, 2018

Copy link to clipboard

Copied

The code use to get tool presets seems to need CC 2018 or better.  I could be wrong for I no longer have CC 2015, CC 2015,5 and CC 2017 installed on my machine. I rejected those version of Photoshop. CC 2018 IMO is as good as CC 2017 where CC 2015 and CC 2015.5 have bugs the made then Bad  Photoshop versions because of ScriptUI and Scripting problem IMO.

A scripting problem add in CC 205.5 is one that Adobe wants from their BS replay. Seems that Adobe can  not tell the Metadata field info instructions is not metadata copyright  Its OK for Save for Web to strip and PS File into to set it to whatever  you want.  It not OK you a script to reset metadata Info because Adobe feel there may be a copyright information that Adobe Photoshop routinely strips.  BS is BS

Photoshop CC 2015.5: Script Metadata assigment error | Photoshop Family Customer Community 

I fixed Adobe garbage by adding garbage Adobe scripting has no problem restoring garbage Open Document and new document evenys will add garbage if it needs to get around Adobe BS.

if (app.activeDocument.info.instructions.indexOf("Garbage") == -1 ) app.activeDocument.info.instructions = app.activeDocument.info.instructions + "Garbage";  

X's Presetlisted does not fumnction in CC 2014 an empty window just opens

JJMack

Votes

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
People's Champ ,
Dec 16, 2018 Dec 16, 2018

Copy link to clipboard

Copied

Try using

var list2 = List.getObjectValue(7).getList(stringIDToTypeID("title"));      

...

var str2 = list2.getString(i);

instead of

var list2 = List.getObjectValue(7).getList(stringIDToTypeID("class"));      

...

var str2 = typeIDToStringID(list2.getClass(i));

So you get a localized tool name.

Knowing it, you yourself can get the required ID for the class of the tool, if of course you need it.

Votes

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
Contributor ,
Dec 28, 2018 Dec 28, 2018

Copy link to clipboard

Copied

I modified the script as r-bin suggested, but now when I run this code in CC2014, the alert box is empty. Is there something I am missing here?

alert(getToolPresetNames(currentToolName()).join("\n"));    

    

function getToolPresetNames(tool) {      

    var ref = new ActionReference();      

    ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("presetManager"));    

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

    var appDesc = executeActionGet(ref);      

    var List = appDesc.getList(stringIDToTypeID("presetManager"));      

    var presetNames = [];      

    var list = List.getObjectValue(7).getList(charIDToTypeID("Nm  "));      

    var list2 = List.getObjectValue(7).getList(stringIDToTypeID("title"));          

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

        var str = list.getString(i);      

        var str2 = list2.getString(i);      

       // presetNames.push([str,str2]);      

        if (str2==tool) presetNames.push([str,]);         

    }      

    return presetNames;      

}; 

 

 

function currentToolName() { 

var ref = new ActionReference(); 

ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("tool")); 

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

var applicationDesc = executeActionGet(ref); 

//alert(typeIDToStringID(applicationDesc.getEnumerationType(stringIDToTypeID("tool")))); 

return(typeIDToStringID(applicationDesc.getEnumerationType(stringIDToTypeID("tool")))); 

}

Votes

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
People's Champ ,
Dec 29, 2018 Dec 29, 2018

Copy link to clipboard

Copied

alert(getCurrToolPresetNames().toSource());

function getCurrToolPresetNames()

    {        

    var result = new Array();

    var r = new ActionReference();

    r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("tool"));

    r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

    var tool = executeActionGet(r).getEnumerationType(stringIDToTypeID("tool")); 

    var r = new ActionReference();

    r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("presetManager"));

    r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

    var l1 = executeActionGet(r).getList(stringIDToTypeID("presetManager")).getObjectValue(7).getList(stringIDToTypeID("name"));        

    var l2 = executeActionGet(r).getList(stringIDToTypeID("presetManager")).getObjectValue(7).getList(stringIDToTypeID("title"));        

    if (l1.count != l2.count) throw("List count error");

    for (var i = 0; i < l1.count; i++) if (stringIDToTypeID(tool_class(l2.getString(i))) == tool) result.push(l1.getString(i));

    return result;        

    };   

////////////////////////////////////////////////////////////////////////////////////////////

function tool_class(name)

    {

    switch(name)

        {

        case "Color Replacement Tool":      return "colorReplacementBrushTool";

        case "Healing Brush Tool":          return "magicStampTool";

        case "Red Eye Tool":                return "redEyeTool";

        case "Rectangular Marquee Tool":    return "marqueeRectTool";

        case "Elliptical Marquee Tool":     return "marqueeEllipTool";

        case "Single Row Marquee Tool":     return "marqueeSingleRowTool";

        case "Single Column Marquee Tool":  return "marqueeSingleColumnTool";

        case "Move Tool":                   return "moveTool";                             

        case "Artboard Tool":               return "artboardTool";                         

        case "Lasso Tool":                  return "lassoTool";                            

        case "Polygonal Lasso Tool":        return "polySelTool";                          

        case "Magnetic Lasso Tool":         return "magneticLassoTool";                    

        case "Magic Wand Tool":             return "magicWandTool";                        

        case "Quick Selection Tool":        return "quickSelectTool";                      

        case "Crop Tool":                   return "cropTool";                             

        case "Perspective Crop Tool":       return "perspectiveCropTool";                  

        case "Slice Tool":                  return "sliceTool";                            

        case "Paint Bucket Tool":           return "bucketTool";                           

        case "Path Selection Tool":         return "pathComponentSelectTool";              

        case "Pen Tool":                    return "penTool";                              

        case "Freeform Pen Tool":           return "freeformPenTool";                      

        case "Curvature Pen Tool":          return "curvaturePenTool";                     

        case "Horizontal Type Tool":        return "typeCreateOrEditTool";                 

        case "Vertical Type Tool":          return "typeVerticalCreateOrEditTool";         

        case "Horizontal Type Mask Tool":   return "typeCreateMaskTool";                   

        case "Vertical Type Mask Tool":     return "typeVerticalCreateMaskTool";           

        case "Rectangle Tool":              return "rectangleTool";                        

        case "Rounded Rectangle Tool":      return "roundedRectangleTool";                 

        case "Ellipse Tool":                return "ellipseTool";                          

        case "Polygon Tool":                return "polygonTool";                          

        case "Line Tool":                   return "lineTool";                             

        case "Custom Shape Tool":           return "customShapeTool";                      

        case "Eyedropper Tool":             return "eyedropperTool";                       

        case "Color Sampler Tool":          return "colorSamplerTool";                     

        case "Note Tool":                   return "textAnnotTool";                        

        case "Patch Tool":                  return "patchSelection";                       

        case "Content-Aware Move Tool":     return "recomposeSelection";                   

        case "Spot Healing Brush Tool":     return "spotHealingBrushTool";                 

        case "3D Material Eyedropper Tool": return "3DMaterialSelectTool";                 

        case "3D Material Drop Tool":       return "3DMaterialDropTool";                   

        case "Art History Brush Tool":      return "artBrushTool";                         

        case "Blur Tool":                   return "blurTool";                             

        case "Burn Tool":                   return "burnInTool";                           

        case "Clone Stamp Tool":            return "cloneStampTool";                       

        case "Dodge Tool":                  return "dodgeTool";                            

        case "Eraser Tool":                 return "eraserTool";                           

        case "Gradient Tool":               return "gradientTool";                         

        case "History Brush Tool":          return "historyBrushTool";                     

        case "Magic Eraser Tool":           return "magicEraserTool";                      

        case "Mixer Brush Tool":            return "wetBrushTool";                         

        case "Pattern Stamp Tool":          return "patternStampTool";                     

        case "Brush Tool":                  return "paintbrushTool";                       

        case "Pencil Tool":                 return "pencilTool";                           

        case "Background Eraser Tool":      return "backgroundEraserTool";                 

        case "Sharpen Tool":                return "sharpenTool";                          

        case "Smudge Tool":                 return "smudgeTool";                           

        case "Sponge Tool":                 return "saturationTool";                       

        }

    };

Votes

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
Community Expert ,
Dec 29, 2018 Dec 29, 2018

Copy link to clipboard

Copied

Thank You that code does indeed run in older version of PS like CS6.

/* =================================================================================

    Cycling Forward and Backward through Current Tool Presets

=====================================================================================

2018  John J. McAssey (JJMack)

=====================================================================================

    Cycle Current Tool Presets

Run this script via two Fn shortcut keys.

F(n) Forward  Modifier+F(n) Backward

===================================================================================== */

#target photoshop;

app.bringToFront();

// My cycleTool function required three parameters  (tool,Set,list) its modified here not to require a set of tool preset

var tool = currentToolName(); // Photoshop Current Tool name

var presetSet  = ''; // Special case use Currently loaded tool presets only.

var presetNames = getCurrToolPresetNames(); // Get Current tool loaded Preset to cycle through.

if (presetNames=="") alert(tool + " hast no current preesets."); // Current Tool has no loaded Presets

else cycleTool(tool,presetSet,presetNames);  // use modified function below

// End Required Parameters

// =================================================== End Main line Code ======================================================== //

// Modified version of my cycleTool function code added to only handle the current Tool currently loaded tool preset.  When toolPresetSet is "".   

function cycleTool(toolName,toolPresetSet,toolPresetNames){ // alert("CycleTool");

if (currentToolName()!=toolName) { // if user is switching tools try to else switch tool preset

try {selectTool(toolName);} // Insure the tool is select so preset can be selected

catch(e) {alert("Unable to Select the Tool "+toolName); return;} // Tool name wrong or unavailable

if (app.toolSupportsBrushes(app.currentTool)) app.runMenuItem(charIDToTypeID(('TglB'))); //Toggle Brush Palette

return; // Just switch to the tools current setting

}

var desc = new ActionDescriptor(); // Set up Photoshop to remember variables

try {var desc = app.getCustomOptions('Cycle'+toolPresetSet);} // Try to get CustomOption for cycling this tool presets set

catch(e){ // Each Photoshop session this should fail first time reset

    if (toolPresetSet!="" ) { // If the is a set of tool presets see if one can be selected           

try {selectToolPreset(toolPresetNames[0]);} // Insure Tool Presets Set has been loaded

catch(e) { // Will fail if tools presets set is not loaded

if (loadToolPresetSet(toolPresetSet)) { // Load Tool presets set

try {selectToolPreset(toolPresetNames[0]);} // Load sets first preset

catch(e) {alert("Was unable to Select the Tools Preset "+toolPresetNames[0]); return;} // Failed to select preset

}

else {alert("Was unable to load Tools Presets Set "+toolPresetSet); return;} // Failed to load tools presets set

}

desc.putInteger(0,0); // This line save the variable while Photoshop is open,

app.putCustomOptions('Cycle'+toolPresetSet,desc,false ); // Initialize presets set CustomOption for cycling

desc = app.getCustomOptions('Cycle'+toolPresetSet); // Get CustomOption Cycle starting point

}

else {

try {var desc = app.getCustomOptions('Cycle CurrentTool');} // Try to get CustomOption for cycling this tool presets set

catch(e) {

desc.putInteger(0,0); // This line save the variable while Photoshop is open,

app.putCustomOptions('Cycle CurrentTool',desc,false ); // Initialize presets set CustomOption for cycling

desc = app.getCustomOptions('Cycle CurrentTool'); // Get CustomOption Cycle starting point

}

}

    }

var presetNumber = desc.getInteger(0); // Get the preset index

if (ScriptUI.environment.keyboardState.ctrlKey||ScriptUI.environment.keyboardState.altKey||

ScriptUI.environment.keyboardState.shiftKey) { // Previous preset if Ctrl or Alt or Shift key is down

presetNumber = presetNumber-2; // Back up two preset for it will be bumped one

if (presetNumber<0){presetNumber=toolPresetNames.length-1;} // Set preset index to the end of the list

}

if (presetNumber<toolPresetNames.length){desc.putInteger(0,presetNumber+1);} // Update preset index number

else {presetNumber=0; desc.putInteger(0,1);} // Reset preset index pointer to the begging of the list

app.putCustomOptions('Cycle'+toolPresetSet,desc,false); // Put Update the Custom option

//alert( currentToolName() + " " + presetNumber + " " + toolPresetNames[presetNumber]);

try {selectToolPreset(toolPresetNames[presetNumber]);} // Set tool with preset

catch(e) {

if (toolPresetSet=="" ) {alert("Current Tool Preset Failed" ); return;} // Current tool Presets may have reset

if (loadToolPresetSet(toolPresetSet)) { // Load Tool presets set Tool presets may have reset

try {selectToolPreset(toolPresetNames[presetNumber]);} // Set tool with preset

catch(e) {alert("Was unable to Select the Tools Preset "+toolPresetNames[presetNumber]); return;} // Failed to select

}

else {alert("Was unable to load Tools Presets Set "+toolPresetSet); return;} // Failed to load tools presets set

}

};

// =================================================== Helper functions ===================================================== //

function selectTool(tool) {

    var desc9 = new ActionDescriptor();

        var ref7 = new ActionReference();

        ref7.putClass( app.stringIDToTypeID(tool) );

    desc9.putReference( app.charIDToTypeID('null'), ref7 );

    executeAction( app.charIDToTypeID('slct'), desc9, DialogModes.NO );

};

function selectToolPreset(PresetName) {

var desc = new ActionDescriptor();

var ref = new ActionReference();

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

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

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

}

function loadToolPresetSet(SetName) {

returncode = true;

var scriptLocation = String(findScript());

var path = scriptLocation.substr(0, scriptLocation.lastIndexOf("/") + 1 ) ;

var SetFile = new File(path + SetName + ".tpl");   // Requited to be in the script's folder

if (!SetFile.exists) { returncode = false; }

else {

var desc = new ActionDescriptor();

var ref = new ActionReference();

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

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

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

desc.putPath( charIDToTypeID( "T   " ), new File( SetFile ) );

desc.putBoolean( charIDToTypeID( "Appe" ), true );

try {executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );}

catch(e) { returncode = false; }

}

return returncode ;

}

function findScript() {// Find the location where this script resides

var where = "";

try { FORCEERROR = FORCERRROR;}

catch(err) { where = File(err.fileName);}

return where ;

}

function currentToolName() {

var ref = new ActionReference();

ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("tool"));

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

var applicationDesc = executeActionGet(ref);

//alert(typeIDToStringID(applicationDesc.getEnumerationType(stringIDToTypeID("tool"))));

return(typeIDToStringID(applicationDesc.getEnumerationType(stringIDToTypeID("tool"))));

}

function getCurrToolPresetNames()  

    {          

    var result = new Array(); 

 

    var r = new ActionReference(); 

    r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("tool")); 

    r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum")); 

    var tool = executeActionGet(r).getEnumerationType(stringIDToTypeID("tool"));   

 

    var r = new ActionReference(); 

    r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("presetManager")); 

    r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum")); 

 

    var l1 = executeActionGet(r).getList(stringIDToTypeID("presetManager")).getObjectValue(7).getList(stringIDToTypeID("name"));          

    var l2 = executeActionGet(r).getList(stringIDToTypeID("presetManager")).getObjectValue(7).getList(stringIDToTypeID("title"));          

 

    if (l1.count != l2.count) throw("List count error"); 

 

    for (var i = 0; i < l1.count; i++) if (stringIDToTypeID(tool_class(l2.getString(i))) == tool) result.push(l1.getString(i)); 

 

    return result;          

    };     

 

//////////////////////////////////////////////////////////////////////////////////////////// 

function tool_class(name)  

    {  

    switch(name) 

        { 

        case "Color Replacement Tool":      return "colorReplacementBrushTool"; 

        case "Healing Brush Tool":          return "magicStampTool"; 

        case "Red Eye Tool":                return "redEyeTool"; 

        case "Rectangular Marquee Tool":    return "marqueeRectTool"; 

        case "Elliptical Marquee Tool":     return "marqueeEllipTool"; 

        case "Single Row Marquee Tool":     return "marqueeSingleRowTool"; 

        case "Single Column Marquee Tool":  return "marqueeSingleColumnTool"; 

        case "Move Tool":                   return "moveTool";                               

        case "Artboard Tool":               return "artboardTool";                           

        case "Lasso Tool":                  return "lassoTool";                              

        case "Polygonal Lasso Tool":        return "polySelTool";                            

        case "Magnetic Lasso Tool":         return "magneticLassoTool";                      

        case "Magic Wand Tool":             return "magicWandTool";                          

        case "Quick Selection Tool":        return "quickSelectTool";                        

        case "Crop Tool":                   return "cropTool";                               

        case "Perspective Crop Tool":       return "perspectiveCropTool";                    

        case "Slice Tool":                  return "sliceTool";                              

        case "Paint Bucket Tool":           return "bucketTool";                             

        case "Path Selection Tool":         return "pathComponentSelectTool";                

        case "Pen Tool":                    return "penTool";                                

        case "Freeform Pen Tool":           return "freeformPenTool";                        

        case "Curvature Pen Tool":          return "curvaturePenTool";                       

        case "Horizontal Type Tool":        return "typeCreateOrEditTool";                   

        case "Vertical Type Tool":          return "typeVerticalCreateOrEditTool";           

        case "Horizontal Type Mask Tool":   return "typeCreateMaskTool";                     

        case "Vertical Type Mask Tool":     return "typeVerticalCreateMaskTool";             

        case "Rectangle Tool":              return "rectangleTool";                          

        case "Rounded Rectangle Tool":      return "roundedRectangleTool";                   

        case "Ellipse Tool":                return "ellipseTool";                            

        case "Polygon Tool":                return "polygonTool";                            

        case "Line Tool":                   return "lineTool";                               

        case "Custom Shape Tool":           return "customShapeTool";                        

        case "Eyedropper Tool":             return "eyedropperTool";                         

        case "Color Sampler Tool":          return "colorSamplerTool";                       

        case "Note Tool":                   return "textAnnotTool";                          

        case "Patch Tool":                  return "patchSelection";                         

        case "Content-Aware Move Tool":     return "recomposeSelection";                     

        case "Spot Healing Brush Tool":     return "spotHealingBrushTool";                   

        case "3D Material Eyedropper Tool": return "3DMaterialSelectTool";                   

        case "3D Material Drop Tool":       return "3DMaterialDropTool";                     

        case "Art History Brush Tool":      return "artBrushTool";                           

        case "Blur Tool":                   return "blurTool";                               

        case "Burn Tool":                   return "burnInTool";                             

        case "Clone Stamp Tool":            return "cloneStampTool";                         

        case "Dodge Tool":                  return "dodgeTool";                              

        case "Eraser Tool":                 return "eraserTool";                             

        case "Gradient Tool":               return "gradientTool";                           

        case "History Brush Tool":          return "historyBrushTool";                       

        case "Magic Eraser Tool":           return "magicEraserTool";                        

        case "Mixer Brush Tool":            return "wetBrushTool";                           

        case "Pattern Stamp Tool":          return "patternStampTool";                       

        case "Brush Tool":                  return "paintbrushTool";                         

        case "Pencil Tool":                 return "pencilTool";                             

        case "Background Eraser Tool":      return "backgroundEraserTool";                   

        case "Sharpen Tool":                return "sharpenTool";                            

        case "Smudge Tool":                 return "smudgeTool";                             

        case "Sponge Tool":                 return "saturationTool";                         

        }  

    }; 

JJMack

Votes

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
Community Expert ,
Dec 15, 2018 Dec 15, 2018

Copy link to clipboard

Copied

/* =================================================================================

    Cycling Forward and Backward through Current Tool Presets

=====================================================================================

2018  John J. McAssey (JJMack)

=====================================================================================

    Cycle Current Tool Presets

Run that script via shortcut keys. Set two Shortcuts keys

F(n) Forward  Modifier+F(n) Backward

===================================================================================== */

#target photoshop;

app.bringToFront();

if (!CheckVersion(19)) { alert("Photoshop version 19+ is required.")}

else {

// Required three parameters  tool,Set,list

var tool = currentToolName(); // Photoshop Tool name your Presets set is for. Only one tool's presets

var presetSet  = ''; // Current preset only no Presets *.tpl file  special case

var presetNames = getToolPresetNames(currentToolName()); // Current tool Preset to cycle through.

if (presetNames=="") alert(tool + " hast no current preesets.");

else cycleTool(tool,presetSet,presetNames);

// End Required Parameters

}

// =================================================== Main function ======================================================== //

//Special case code added to only handle the current Tool currently loaded tool preset.  When toolPresetSet is "".   

function cycleTool(toolName,toolPresetSet,toolPresetNames){ // alert("CycleTool");

if (currentToolName()!=toolName) { // if user is switching tools try to else switch tool preset

try {selectTool(toolName);} // Insure the tool is select so preset can be selected

catch(e) {alert("Unable to Select the Tool "+toolName); return;} // Tool name wrong or unavailable

if (app.toolSupportsBrushes(app.currentTool)) app.runMenuItem(charIDToTypeID(('TglB'))); //Toggle Brush Palette

return; // Just switch to the tools current setting

}

var desc = new ActionDescriptor(); // Set up Photoshop to remember variables

try {var desc = app.getCustomOptions('Cycle'+toolPresetSet);} // Try to get CustomOption for cycling this tool presets set

catch(e){ // Each Photoshop session this should fail first time reset

    if (toolPresetSet!="" ) {

try {selectToolPreset(toolPresetNames[0]);} // Insure Tool Presets Set has been loaded

catch(e) { // Will fail if tools presets set is not loaded

if (loadToolPresetSet(toolPresetSet)) { // Load Tool presets set

try {selectToolPreset(toolPresetNames[0]);} // Load sets first preset

catch(e) {alert("Was unable to Select the Tools Preset "+toolPresetNames[0]); return;} // Failed to select preset

}

else {alert("Was unable to load Tools Presets Set "+toolPresetSet); return;} // Failed to load tools presets set

}

desc.putInteger(0,0); // This line save the variable while Photoshop is open,

app.putCustomOptions('Cycle'+toolPresetSet,desc,false ); // Initialize presets set CustomOption for cycling

desc = app.getCustomOptions('Cycle'+toolPresetSet); // Get CustomOption Cycle starting point

}

else {

try {var desc = app.getCustomOptions('Cycle CurrentTool');} // Try to get CustomOption for cycling this tool presets set

catch(e) {

desc.putInteger(0,0); // This line save the variable while Photoshop is open,

app.putCustomOptions('Cycle CurrentTool',desc,false ); // Initialize presets set CustomOption for cycling

desc = app.getCustomOptions('Cycle CurrentTool'); // Get CustomOption Cycle starting point

}

}

    }

var presetNumber = desc.getInteger(0); // Get the preset index

if (ScriptUI.environment.keyboardState.ctrlKey||ScriptUI.environment.keyboardState.altKey||

ScriptUI.environment.keyboardState.shiftKey) { // Previous preset if Ctrl or Alt or Shift key is down

presetNumber = presetNumber-2; // Back up two preset for it will be bumped one

if (presetNumber<0){presetNumber=toolPresetNames.length-1;} // Set preset index to the end of the list

}

if (presetNumber<toolPresetNames.length){desc.putInteger(0,presetNumber+1);} // Update preset index number

else {presetNumber=0; desc.putInteger(0,1);} // Reset preset index pointer to the begging of the list

app.putCustomOptions('Cycle'+toolPresetSet,desc,false); // Put Update the Custom option

//alert( currentToolName() + " " + presetNumber + " " + toolPresetNames[presetNumber]);

try {selectToolPreset(toolPresetNames[presetNumber]);} // Set tool with preset

catch(e) {

if (toolPresetSet=="" ) {alert("Current Tool Preset Failed" ); return;} // Current tool Presets may have reset

if (loadToolPresetSet(toolPresetSet)) { // Load Tool presets set Tool presets may have reset

try {selectToolPreset(toolPresetNames[presetNumber]);} // Set tool with preset

catch(e) {alert("Was unable to Select the Tools Preset "+toolPresetNames[presetNumber]); return;} // Failed to select

}

else {alert("Was unable to load Tools Presets Set "+toolPresetSet); return;} // Failed to load tools presets set

}

};

// =================================================== Helper functions ===================================================== //

function selectTool(tool) {

    var desc9 = new ActionDescriptor();

        var ref7 = new ActionReference();

        ref7.putClass( app.stringIDToTypeID(tool) );

    desc9.putReference( app.charIDToTypeID('null'), ref7 );

    executeAction( app.charIDToTypeID('slct'), desc9, DialogModes.NO );

};

function selectToolPreset(PresetName) {

var desc = new ActionDescriptor();

var ref = new ActionReference();

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

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

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

}

function loadToolPresetSet(SetName) {

returncode = true;

var scriptLocation = String(findScript());

var path = scriptLocation.substr(0, scriptLocation.lastIndexOf("/") + 1 ) ;

var SetFile = new File(path + SetName + ".tpl");   // Requited to be in the script's folder

if (!SetFile.exists) { returncode = false; }

else {

var desc = new ActionDescriptor();

var ref = new ActionReference();

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

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

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

desc.putPath( charIDToTypeID( "T   " ), new File( SetFile ) );

desc.putBoolean( charIDToTypeID( "Appe" ), true );

try {executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );}

catch(e) { returncode = false; }

}

return returncode ;

}

function findScript() {// Find the location where this script resides

var where = "";

try { FORCEERROR = FORCERRROR;}

catch(err) { where = File(err.fileName);}

return where ;

}

function currentToolName() {

var ref = new ActionReference();

ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("tool"));

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

var applicationDesc = executeActionGet(ref);

//alert(typeIDToStringID(applicationDesc.getEnumerationType(stringIDToTypeID("tool"))));

return(typeIDToStringID(applicationDesc.getEnumerationType(stringIDToTypeID("tool"))));

}

   

function getToolPresetNames(tool) {     

    var ref = new ActionReference();     

    ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("presetManager"));   

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

    var appDesc = executeActionGet(ref);     

    var List = appDesc.getList(stringIDToTypeID("presetManager"));     

    var presetNames = [];     

    var list = List.getObjectValue(7).getList(charIDToTypeID("Nm  "));     

    var list2 = List.getObjectValue(7).getList(stringIDToTypeID("class"));      

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

        var str = list.getString(i);     

        var str2 = typeIDToStringID(list2.getClass(i));     

        if (str2==tool) presetNames.push(str);        

    }     

    return presetNames;     

};

function CheckVersion(PSV) {

var numberArray = version.split(".");

if ( numberArray[0] < PSV ) { return false; }

return true;

}

JJMack

Votes

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 15, 2018 Dec 15, 2018

Copy link to clipboard

Copied

#target photoshop;

app.bringToFront();

var ver = app.version.match(/\d+/);

var toolPresets = getToolPresetNames();

var tools =[];

for(var x in toolPresets){tools.push(toolPresets[1].toString());};

tools = ReturnUniqueSortedList(tools);

var win = new Window("dialog","Preset Tools",undefined,{closeButton: true});

win.p1= win.add("panel", undefined, undefined, {borderStyle:"black"});

win.g1 = win.p1.add("group");

win.g1.orientation = "row";

win.title = win.g1.add("statictext",undefined,"Tool Presets");

var g = win.title.graphics;

g.font = ScriptUI.newFont("Georgia","BOLDITALIC",22);

win.g10 = win.p1.add("group");

win.g10.orientation = "row";

win.g10.dd1 = win.g10.add("dropdownlist");

win.g10.dd1.preferredSize=[200,20];

for(var p in tools){win.g10.dd1.add("item",tools

.toString());}

win.g10.dd2 = win.g10.add("dropdownlist");

win.g10.dd2.preferredSize=[200,20];

var tmp=[];

for(var z in toolPresets){

    if(toolPresets[1].toString() == tools[0].toString()) tmp.push(toolPresets[0]);

    }

tmp=tmp.sort();

for(var y in tmp){win.g10.dd2.add("item",tmp.toString());}

win.g10.dd1.selection=0;

win.g10.dd2.selection=0;

win.g10.dd1.onChange = function() {

tmp=[];

win.g10.dd2.removeAll();

for(var z in toolPresets){

    if(toolPresets[1].toString() == tools[win.g10.dd1.selection.index].toString()) tmp.push(toolPresets[0]);

    }

tmp=tmp.sort();

for(var y in tmp){win.g10.dd2.add("item",tmp.toString());}

win.g10.dd2.selection=0;

}

win.g100 = win.p1.add("group");

win.g100.orientation = "row";

win.g100.bu1 = win.g100.add("button",undefined,"Use Preset");

win.g100.bu2 = win.g100.add("button",undefined,"Cancel");

win.g100.bu1.preferredSize=[150,40];

win.g100.bu2.preferredSize=[150,40];

win.g100.bu1.onClick=function(){

win.close(0);

var selTool = win.g10.dd1.selection.text.toString().replace(/\s+/g,""); 

selTool = selTool.charAt(0).toLowerCase() + selTool.substr(1); 

//if(selTool == "verticalTypeTool") selTool ="typeVerticalCreateOrEditTool"; 

selectTool(selTool);

selectToolPreset(win.g10.dd2.selection.text.toString());

}

win.show();

function getToolPresetNames() {     

    var ref = new ActionReference();     

    ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("presetManager"));   

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

    var appDesc = executeActionGet(ref);     

    var List = appDesc.getList(stringIDToTypeID("presetManager"));     

    var presetNames = [];     

    var list = List.getObjectValue(7).getList(charIDToTypeID("Nm  "));     

    var list2 = List.getObjectValue(7).getList(stringIDToTypeID("class"));      

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

        var str = list.getString(i);     

        var str2 = typeIDToStringID(list2.getClass(i));     

        presetNames.push([str,str2]);     

    }     

    return presetNames;     

};  

function ReturnUniqueSortedList(ArrayName){

var unduped = new Object;

for (var i = 0; i < ArrayName.length; i++) {  

unduped[ArrayName] = ArrayName;

}

var uniques = new Array;for (var k in unduped) {

   uniques.push(unduped);

   }

uniques.sort();

return uniques;

}

function selectToolPreset(TOOL) {

    var desc = new ActionDescriptor();

        var ref = new ActionReference();

        ref.putName( stringIDToTypeID('toolPreset'),TOOL );

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

    try{

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

    }catch(e){/*$.writeln("tool = " + TOOL + "\n" + e);*/}

};

function selectTool(tool) {

    var desc = new ActionDescriptor();

        var ref = new ActionReference();

        ref.putClass( app.stringIDToTypeID(tool) );

    desc.putReference( app.charIDToTypeID('null'), ref );

    try{

    executeAction( app.charIDToTypeID('slct'), desc, DialogModes.NO );

    }catch(e){/*$.writeln("tool = " + tool + "\n" + e);*/}

};

Votes

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
Contributor ,
Jan 20, 2019 Jan 20, 2019

Copy link to clipboard

Copied

The code below from r-bin is excellent - and it works in CC2014.

It gets a list of all tool presets of the "current" tool.

Let's say we want to get a list of only 'smudge' tool presets. How do we modify the code to do that? I have tried everything in my power to do so all day, and have not been able to solve it. What do we need to add to the code below so that it ONLY shows a list of 'smudge' tool presets?

  1. alert(getCurrToolPresetNames().toSource()); 
  2.  
  3. function getCurrToolPresetNames()  
  4.     {          
  5.     var result = new Array(); 
  6.  
  7.     var r = new ActionReference(); 
  8.     r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("tool")); 
  9.     r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum")); 
  10.     var tool = executeActionGet(r).getEnumerationType(stringIDToTypeID("tool"));   
  11.  
  12.     var r = new ActionReference(); 
  13.     r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("presetManager")); 
  14.     r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum")); 
  15.  
  16.     var l1 = executeActionGet(r).getList(stringIDToTypeID("presetManager")).getObjectValue(7).getList(stringIDToTypeID("name"));          
  17.     var l2 = executeActionGet(r).getList(stringIDToTypeID("presetManager")).getObjectValue(7).getList(stringIDToTypeID("title"));          
  18.  
  19.     if (l1.count != l2.count) throw("List count error"); 
  20.  
  21.     for (var i = 0; i < l1.count; i++) if (stringIDToTypeID(tool_class(l2.getString(i))) == tool) result.push(l1.getString(i)); 
  22.  
  23.     return result;          
  24.     };     
  25.  
  26. //////////////////////////////////////////////////////////////////////////////////////////// 
  27. function tool_class(name)  
  28.     {  
  29.     switch(name) 
  30.         { 
  31.         case "Color Replacement Tool":      return "colorReplacementBrushTool"; 
  32.         case "Healing Brush Tool":          return "magicStampTool"; 
  33.         case "Red Eye Tool":                return "redEyeTool"; 
  34.         case "Rectangular Marquee Tool":    return "marqueeRectTool"; 
  35.         case "Elliptical Marquee Tool":     return "marqueeEllipTool"; 
  36.         case "Single Row Marquee Tool":     return "marqueeSingleRowTool"; 
  37.         case "Single Column Marquee Tool":  return "marqueeSingleColumnTool"; 
  38.         case "Move Tool":                   return "moveTool";                               
  39.         case "Artboard Tool":               return "artboardTool";                           
  40.         case "Lasso Tool":                  return "lassoTool";                              
  41.         case "Polygonal Lasso Tool":        return "polySelTool";                            
  42.         case "Magnetic Lasso Tool":         return "magneticLassoTool";                      
  43.         case "Magic Wand Tool":             return "magicWandTool";                          
  44.         case "Quick Selection Tool":        return "quickSelectTool";                        
  45.         case "Crop Tool":                   return "cropTool";                               
  46.         case "Perspective Crop Tool":       return "perspectiveCropTool";                    
  47.         case "Slice Tool":                  return "sliceTool";                              
  48.         case "Paint Bucket Tool":           return "bucketTool";                             
  49.         case "Path Selection Tool":         return "pathComponentSelectTool";                
  50.         case "Pen Tool":                    return "penTool";                                
  51.         case "Freeform Pen Tool":           return "freeformPenTool";                        
  52.         case "Curvature Pen Tool":          return "curvaturePenTool";                       
  53.         case "Horizontal Type Tool":        return "typeCreateOrEditTool";                   
  54.         case "Vertical Type Tool":          return "typeVerticalCreateOrEditTool";           
  55.         case "Horizontal Type Mask Tool":   return "typeCreateMaskTool";                     
  56.         case "Vertical Type Mask Tool":     return "typeVerticalCreateMaskTool";             
  57.         case "Rectangle Tool":              return "rectangleTool";                          
  58.         case "Rounded Rectangle Tool":      return "roundedRectangleTool";                   
  59.         case "Ellipse Tool":                return "ellipseTool";                            
  60.         case "Polygon Tool":                return "polygonTool";                            
  61.         case "Line Tool":                   return "lineTool";                               
  62.         case "Custom Shape Tool":           return "customShapeTool";                        
  63.         case "Eyedropper Tool":             return "eyedropperTool";                         
  64.         case "Color Sampler Tool":          return "colorSamplerTool";                       
  65.         case "Note Tool":                   return "textAnnotTool";                          
  66.         case "Patch Tool":                  return "patchSelection";                         
  67.         case "Content-Aware Move Tool":     return "recomposeSelection";                     
  68.         case "Spot Healing Brush Tool":     return "spotHealingBrushTool";                   
  69.         case "3D Material Eyedropper Tool": return "3DMaterialSelectTool";                   
  70.         case "3D Material Drop Tool":       return "3DMaterialDropTool";                     
  71.         case "Art History Brush Tool":      return "artBrushTool";                           
  72.         case "Blur Tool":                   return "blurTool";                               
  73.         case "Burn Tool":                   return "burnInTool";                             
  74.         case "Clone Stamp Tool":            return "cloneStampTool";                         
  75.         case "Dodge Tool":                  return "dodgeTool";                              
  76.         case "Eraser Tool":                 return "eraserTool";                             
  77.         case "Gradient Tool":               return "gradientTool";                           
  78.         case "History Brush Tool":          return "historyBrushTool";                       
  79.         case "Magic Eraser Tool":           return "magicEraserTool";                        
  80.         case "Mixer Brush Tool":            return "wetBrushTool";                           
  81.         case "Pattern Stamp Tool":          return "patternStampTool";                       
  82.         case "Brush Tool":                  return "paintbrushTool";                         
  83.         case "Pencil Tool":                 return "pencilTool";                             
  84.         case "Background Eraser Tool":      return "backgroundEraserTool";                   
  85.         case "Sharpen Tool":                return "sharpenTool";                            
  86.         case "Smudge Tool":                 return "smudgeTool";                             
  87.         case "Sponge Tool":                 return "saturationTool";                         
  88.         }  
  89.     }; 

Votes

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
Community Expert ,
Jan 20, 2019 Jan 20, 2019

Copy link to clipboard

Copied

You would need to change the script to get to preset for the tool you are interested in.  The beginning of the script retrieve the current tool.  Then gets that tools current presets.  You would get the tool preset instead for the tool you are interested in. You would set the var tool to the name of the tool you are interests in.  The function tool_class has the names of all tools. All Photoshop Tool Presets are retrieved  then line 21 uses that var tool to  extract that tool preset and push them into the results.

JJMack

Votes

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
LEGEND ,
Jan 20, 2019 Jan 20, 2019

Copy link to clipboard

Copied

I tried the above code and if I have selected tool but that wasn't avialable in Tool Presets it alerted [], but when it was there, it alerted me array of all presets for this tool. So I can confirm you don't have to modify the code. It is working for me in CC 2019, until you mean something that I don't understand, so probably you want to change 21th line to:

for(i = 0; i < l1.count; i++) if (/Smudge Tool/.test(l1.getString(i))) result.push(l1.getString(i))

Votes

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
People's Champ ,
Jan 20, 2019 Jan 20, 2019

Copy link to clipboard

Copied

alert(getToolPresetNames("Smudge Tool"));   

// For any non-English version of Photoshop

alert(getToolPresetNames(localize("$$$/Toolbar/ToolTips/SmudgeTool")));   

// For the Russian version of Photoshop

alert(getToolPresetNames('Инструмент "Палец"'));   

   

function getToolPresetNames(tool_name)    

    {            

    var result = new Array();   

    var r = new ActionReference();   

    r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("presetManager"));   

    r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));       

    var l1 = executeActionGet(r).getList(stringIDToTypeID("presetManager")).getObjectValue(7).getList(stringIDToTypeID("name"));            

    var l2 = executeActionGet(r).getList(stringIDToTypeID("presetManager")).getObjectValue(7).getList(stringIDToTypeID("title"));            

   

    if (l1.count != l2.count) throw("List count error");   

   

    for (var i = 0; i < l1.count; i++) if (l2.getString(i) == tool_name) result.push(l1.getString(i));   

   

    return result;            

    }; 

Votes

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