18 Replies Latest reply on Jan 16, 2017 12:45 PM by marior90336416

    Cycle through Tool Presets with shortcut?

    marior90336416

      Is it actually possible to cycle through the Tool Presets just like it is with brushes using shortcuts?

      I've searched all over google and the forums and while I've found some posts with similar question, it looked like a dead end.

       

      I know it is possible to select specific Tool Preset using a shortcut/action but I wanted to know if they can be cycled, like "next tool preset,", "previous tool preset".

       

      Can a script do that?

       

      Thanks

        • 1. Re: Cycle through Tool Presets with shortcut?
          JJMack Most Valuable Participant

          If you know the tool you want to cycle through it loaded presets you should be able to.  I qite sure I have seen a script posted here that retrieve tool loaded presets names  Try the search

          https://forums.adobe.com/search.jspa?place=%2Fplaces%2F1383833&q=preset+list .

          • 2. Re: Cycle through Tool Presets with shortcut?
            marior90336416 Level 1

            Thanks JJMack, let's see if I got right what you mean. Let's say I have a set of smudge presets on the Tool presets. Let's say I have 3 types, Hard, medium, Soft. I can assign a hotkey, say, F6 to load a script that will cycle through them? Like, I select the Hard, press F6, the script load up and move to medium, F6 again, move to Soft. Press F6 again, go to Hard. Is it how it would work?

             

            I haven't tested but I've found this thread

             

            Re: Is it possible to cycle through brushes (tpls) using a script?

            • 3. Re: Cycle through Tool Presets with shortcut?
              marior90336416 Level 1

              I tried the script on that post, put my brushes name there and got this message. Not the the line I've changed hehe.

               

               

              2017-01-13 20_08_02-Error.png

              • 4. Re: Cycle through Tool Presets with shortcut?
                JJMack Most Valuable Participant

                In Xtools the is a Presets lister script it will list all presets. Not Just Tools presets so you can get the names of all presets.  Tool Presets can have any name.  The name may not reflect what tool the preset is for.  There is a problem with selecting a tool preset  if you know the preset but not the tool.  If the user's Photoshop Presets UI has the current tool only box checked only the current tool's presets can be selected by an action or script.  If you know the tool you can select the tool then select the tool preset name.   The problem is a script can not uncheck Photoshop UI current tool only box and has no way to find out if it is checked or not.  If it not checked you can select any loaded preset by name.  That will both select the tool and set to tool settings stored in the tool preset. If the checkbox is checked and a script tries to select a preset that is not for the current tool it will generate an error the script can catch a try changing tools an retry selecting the preset etc. What too is a Peanut Dash ?

                Capture.jpg

                • 5. Re: Cycle through Tool Presets with shortcut?
                  JJMack Most Valuable Participant

                  Select the Brush tool first so you can select its presets. Your current tool only checkbox is checked.

                  • 6. Re: Cycle through Tool Presets with shortcut?
                    JJMack Most Valuable Participant

                    This may help

                    var ToolName       = "paintbrushTool";              // Brush Tool
                    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.
                    Main(ToolName,ToolPresetName,ToolPresetSet);
                    
                    
                    function Main(Tool,Preset,Set) {
                      try {SelectTool(Tool);}
                      catch(e) { alert('Select Tool "' + Tool + '" failed'); return;} 
                      try {SelectToolPreset(ToolPresetName);}
                      catch(e) {
                         if (LoadToolPresetSet(ToolPresetSet)) {
                            try {SelectToolPreset(ToolPresetName);}
                            catch(e) {alert('Select Tool Preset "' + ToolPresetName + '" failed');}
                         }
                         else {alert("Was unable to load Tools Presets Set " + ToolPresetSet);} 
                      }
                    }
                    
                    // =================================================== Helper functions ===================================================== // 
                    function SelectTool(tool) {
                        var desc = new ActionDescriptor();
                            var ref = new ActionReference();
                            ref.putClass( app.stringIDToTypeID(tool) );
                        desc.putReference( app.charIDToTypeID('null'), ref );
                        executeAction( app.charIDToTypeID('slct'), desc, 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 {
                      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 ;
                    }
                    
                    
                    
                    
                    
                    
                    • 7. Re: Cycle through Tool Presets with shortcut?
                      marior90336416 Level 1

                      Cool, I found Xtools, installed and found the Preset Listener in the Actions. I tried to run and got the following message

                       

                      "General Photoshop error occurred. This functionality may not be available at this version of Photoshop.

                      -<no additional information available>

                       

                      I checked the action and it says" -- "File: File or folder not found" so this might be the culprit. Any idea how to fix this?

                       

                      Thanks in advance.

                      • 8. Re: Cycle through Tool Presets with shortcut?
                        marior90336416 Level 1

                        Thanks for the script JJMack, I'll try and see how it goes!

                        • 9. Re: Cycle through Tool Presets with shortcut?
                          marior90336416 Level 1

                          Got, it I tried the script, replaced the variables but so far I only get the script to select one tool, instead of cycling through them. What I'm doing wrong?

                           

                          Thanks

                          • 10. Re: Cycle through Tool Presets with shortcut?
                            JJMack Most Valuable Participant

                            I'm not writing your script for you. I am just trying to help you understand what you need to do to select a preset and to load a preset if it is not loaded.  If you want to cycle through a list of presets you need to create an array of presets names  in the script.  And create an script option or external  list index  to notes where in the list you are.  So each time the script is run it can select the  next preset in the list and update the option or external index for the position in the preset array. You need to do that.

                            • 11. Re: Cycle through Tool Presets with shortcut?
                              marior90336416 Level 1

                              Sorry, I misunderstood. I thought the script was supposed to load the list itself.

                              Thanks.

                              • 12. Re: Cycle through Tool Presets with shortcut?
                                JJMack Most Valuable Participant

                                Did you ever search this forum for script that cycle brushes? I wrote I have seen some here. Was not that long ago for it was still in my memory. If you combine what I show you that script the script can make sure the brush preset are loaded

                                 

                                 

                                 

                                Correct AnswerRe: Is it possible to cycle through brushes (tpls) using a script?

                                SuperMerlinLevel 4

                                 

                                Here is an example of cycling through three brushes using thier names.

                                N.B. make sure brushes are selected and the brushes are loaded.

                                 

                                 

                                1. #target photoshop; 
                                2. app.bringToFront(); 
                                3. main(); 
                                4. function main(){ 
                                5.     //Name of Brushes to cycle through 
                                6. var Brushes = ['Flat Angle Left Hand Pose','Chalk 36 pixels','Triangle Pastel']; 
                                7. //Set up Photoshop to remember variables 
                                8. var desc = new ActionDescriptor(); 
                                9. try
                                10. var desc = app.getCustomOptions ( 'toggleBrush' ); 
                                11. }catch(e){ 
                                12.     desc.putInteger ( 0,0 ); 
                                13.     //this line save the variable while Photoshop is open,  
                                14.     //change false to true and it will remember next time Photoshop is opened 
                                15.     app.putCustomOptions( 'toggleBrush', desc, false ); 
                                16.     desc = app.getCustomOptions ( 'toggleBrush' ); 
                                17.     } 
                                18. var brushNumber = desc.getInteger(0); 
                                19. if(brushNumber < Brushes.length){  
                                20. desc.putInteger ( 0, brushNumber + 1); 
                                21. }else
                                22.     brushNumber = 0
                                23.     desc.putInteger ( 0,1); 
                                24.     } 
                                25. app.putCustomOptions( 'toggleBrush', desc, false ); 
                                26. selectBrushByName(Brushes[brushNumber]); 
                                27. }; 
                                28. function selectBrushByName( brushName ){ 
                                29. var desc = new ActionDescriptor(); 
                                30. var ref = new ActionReference(); 
                                31. ref.putName( charIDToTypeID('Brsh'), brushName ); 
                                32. desc.putReference( charIDToTypeID('null'), ref ); 
                                33. executeAction( charIDToTypeID('slct'), desc, DialogModes.NO ); 
                                34. }; 

                                1 person found this helpful

                                • 13. Re: Cycle through Tool Presets with shortcut?
                                  marior90336416 Level 1

                                  Yes I did search I tested that very script, and got an  "Error 8800" with error message attached on the 4th post, from the top to bottom

                                  • 14. Re: Cycle through Tool Presets with shortcut?
                                    JJMack Most Valuable Participant

                                    Did you read the script?  That failed because you failed to create the presets.

                                     

                                    Did you read the text before the script?

                                     

                                    N.B. make sure brushes are selected and the brushes are loaded.

                                    In the script you shoul see the list...

                                    Brushes = ['Flat Angle Left Hand Pose','Chalk 36 pixels','Triangle Pastel'];

                                     

                                    Why not fix up that scrip with the information I gave you and  catch errors like that you could make sure the preset are loaded and that the brush tool is selected.

                                    • 15. Re: Cycle through Tool Presets with shortcut?
                                      marior90336416 Level 1

                                      Hi JJMack, yes I did read and tried to follow the instructions to the best of my capabilities. I tested with 3 presets, "marker_80", "marker_60" and a 40. All loaded up and selected marker 80. I edited the script file to make sure these 3 names were replaced but the flat angle etc. Selected the marker_80. Ran the script, got that error. I'm still getting that error when I run your script before the cycling script.

                                      • 16. Re: Cycle through Tool Presets with shortcut?
                                        JJMack Most Valuable Participant

                                        Did you select the brush tool before you ran your the script will fail like that it you do not have the brush tool selected and your Photoshop's UI is set for current tool only as per "N.B. make sure brushes are selected and the brushes are loaded."

                                         

                                        You could improve on the script using the information I have given you.  It a good way tp learn about scripting. If you wish too.

                                         

                                        If you do want to learn some try and post your code here.  Users here will help you with It.

                                        • 17. Re: Cycle through Tool Presets with shortcut?
                                          JJMack Most Valuable Participant

                                          You disappointed me you never posted your try.  Here is what I came up with for you.

                                           

                                          Here the link this web site messes up script formatting

                                          http://www.mouseprints.net/old/dpr/CycleBrushes.jsx

                                           

                                          /* =================================================================================
                                                        Cycling Forward and Backward through Sets of Tool Presets 
                                          =====================================================================================
                                          2017  John J. McAssey (JJMack)
                                          =====================================================================================
                                          Naming Your Script so that it identify the tool and Presets Set will helpful.
                                              Copy this script to a new Name for each set of presets you want to cycle through.
                                            Run that script via shortcut keys. Set two Shortcuts keys 
                                            F(n) Forward  Modifier+F(n) Backward
                                            There are three required parameters for the cycling function:
                                            1.) Correct Photoshop Tools Name 
                                            2.) Presets Set file name the * part of the *.tpl file
                                            The *.tpl file must reside in the scripts folder
                                            3.) Array of preset names in your desired cycling order
                                          =====================================================================================
                                          Note: This script only deals with Tool Preset files .tpl for tools preset are easily 
                                            reset back to Adobe's defaults using the Preset manager. Tool presets may require
                                            other Photoshop add-ons like brush .abr, patterns .pat, swatch .aco, etc files to
                                            also be loaded this script will not load them this script will only load .tpl 
                                            files if there is a need too. You must add what your presets require to Photoshop
                                          ================================================================================== */
                                          #target photoshop;
                                          app.bringToFront();
                                          // Required three parameters  tool,Set,list
                                          var tool = 'paintbrushTool';                     // Photoshop Tool name your Presets set is for. Only one tool's presets
                                          // For this sample script the presets set can be from DeviantArt "The Sketch Arsenal" that's "the_sketch_arsenal_by_thatld.tpl"
                                          // http://thatld.deviantart.com/art/The-Sketch-Arsenal-161678023 Download link on Top Right of the Page not the one on the bottom
                                          var presetSet  = 'the_sketch_arsenal_by_thatld'; // Presets set name *.tpl file need to be same folder as this Photoshop script.
                                          var presetNames = [                              // Preset names list start. Presets you want to cycle through. Set can have more. 
                                            'Color Brush - Flat',
                                            'Color Brush - Magic Edge',
                                            'Color Pencil - Hard',
                                            'Color Pencil - Soft',
                                            'Drawing Pencil - B Lead',
                                            'Drawing Pencil - Blue Line',
                                            'Drawing Pencil - H Lead',
                                            'Linework Pen - Fine',
                                            'Marker - Lower the Flow to Dry',
                                            'Shading Brush - Pressure Hold',
                                            'Shading Brush - Soft Texture',
                                            'Shading Pencil - General',
                                            'Shading Pencil - Hard',
                                            'Shading Pencil - Soft',
                                            'Sketch Pencil - H Lead',
                                            'Sketch Pencil - The Ultimate!',
                                            'Watercolor Brush - General'
                                            ];                                              // Presets names list end. Order the way you want to cycle through them
                                          // End Required Parameters
                                          cycle(tool,presetSet,presetNames);                  // Cycle Forward and Backward through tool presets set names
                                          // End of Script
                                          // =================================================== Main function ======================================================== //
                                          function cycle(toolName,toolPresetSet,toolPresetNames){
                                            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
                                            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
                                            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
                                              }
                                            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 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
                                            try {selectToolPreset(toolPresetNames[presetNumber]);} // Set tool with preset
                                            catch(e) {alert("Was unable to Select the Tools Preset " + toolPresetNames[presetNumber]);} // Failed to select preset
                                          };
                                          // =================================================== 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 ;
                                          }
                                          /* Photoshop tool names
                                          'moveTool'                     'cloneStampTool'            'typeCreateOrEditTool'
                                          'marqueeRectTool'              'patternStampTool'          'typeVerticalCreateOrEditTool'
                                          'marqueeEllipTool'             'historyBrushTool'          'typeCreateMaskTool'
                                          'marqueeSingleRowTool'         'artBrushTool'              'typeVerticalCreateMaskTool'
                                          'marqueeSingleColumnTool'      'eraserTool'                'pathComponentSelectTool'
                                          'lassoTool'                    'backgroundEraserTool'      'directSelectTool'
                                          'polySelTool'                  'magicEraserTool'           'rectangleTool'
                                          'magneticLassoTool'            'gradientTool'              'roundedRectangleTool'
                                          'quickSelectTool'              'bucketTool'                'ellipseTool'
                                          'magicWandTool'                'blurTool'                  'polygonTool'
                                          'cropTool'                     'sharpenTool'               'lineTool'
                                          'sliceTool'                    'smudgeTool'                'customShapeTool'
                                          'sliceSelectTool'              'dodgeTool'                 'textAnnotTool'
                                          'spotHealingBrushTool'         'burnInTool'                'soundAnnotTool'
                                          'magicStampTool'               'saturationTool'            'eyedropperTool'
                                          'patchSelection'               'penTool'                   'colorSamplerTool'
                                          'redEyeTool'                   'freeformPenTool'           'rulerTool'
                                          'paintbrushTool'               'addKnotTool'               'handTool'
                                          'pencilTool'                   'deleteKnotTool'            'zoomTool'
                                          'colorReplacementBrushTool'    'convertKnotTool'
                                          */
                                          
                                          • 18. Re: Cycle through Tool Presets with shortcut?
                                            marior90336416 Level 1

                                            Thanks JJMack, works like a charm. In fact I was almost giving up finding a way to get rid of that error, when combining both scripts.

                                            I'm sure lots of people will search for a way to cycle through tools in the future and stumble upon this thread and find it very useful.

                                            Thanks again.