Skip to main content
Participant
March 16, 2016
Question

Photoshop tool preset list, by current/active tool?

  • March 16, 2016
  • 7 replies
  • 5006 views

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;

}

This topic has been closed for replies.

7 replies

Inspiring
April 20, 2024

Hello everyone and welcome back

 

To continue this topic... 

 

How can we get the name of the current tool preset being used?

Inspiring
January 22, 2019

r-bin, thank you!! This is excellent and works perfectly. Now we can get an individual list of any tool preset and save it to disk as a .txt file, which can allow us to assemble a better way to select tool presets, which I am still working on

Inspiring
January 20, 2019

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.     }; 
JJMack
Community Expert
Community Expert
January 20, 2019

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
Inspiring
December 15, 2018

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;     

};  

JJMack
Community Expert
Community Expert
December 15, 2018

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

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
Inspiring
December 14, 2018

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?)

JJMack
Community Expert
Community Expert
December 14, 2018

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.

JJMack
JJMack
Community Expert
Community Expert
March 16, 2016

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
Participant
March 16, 2016

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   = [];

JJMack
Community Expert
Community Expert
March 16, 2016

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. 

JJMack
JJMack
Community Expert
Community Expert
March 16, 2016

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