9 Replies Latest reply on Oct 11, 2011 9:50 AM by crydrk

    Load all brushes in brush preset folder at startup

    crydrk Level 1

      I'm wondering if this is possible or if there is a better solution for what I'm trying to do.

       

      What I need to do is have a central repository of brushes or brush sets. I'll create a symlink inside the brushes folder to a space in the local drive. When photoshop is launched, we have scripts in place that will download the newest version of the repository folder to that local drive. (the users do not have permissions for the program files brushes folder) Is there a way to have photoshop load all the brushes automatically without a user having to select a set of brushes and save them?

       

      I'm thinking also maybe there is a corresponding file that holds data for all the sets of brushes. Perhaps I could have a centralized version of this file that I could have downloaded.

       

      We are using photoshop cs5 on a windows environment.

       

      Thanks for any possible help!

        • 1. Re: Load all brushes in brush preset folder at startup
          c.pfaffenbichler Level 9

          Is there a way to have photoshop load all the brushes automatically without a user having to select a set of brushes and save them?

          You could use File > Scripts > Script Events Manager to link a Script that loads the presets to starting the application.

          • 2. Re: Load all brushes in brush preset folder at startup
            Michael L Hale Level 5

            And here is the script to go with c.pfaffenbichler's suggestion.

            // first make a path to the folde where the brushes are stored
            // the user data folder does not need admin rights to read/write
            var USER_PRESETS_FOLDER =
                new Folder(Folder.userData + '/' +
                           localize("$$$/private/AdobeSystemFolder/Adobe=Adobe") + '/' +
                           localize("$$$/private/FolderNames/AdobePhotoshopProductVersionFolder") + '/' +
                           localize("$$$/private/FolderName/UserPresetsFolder/Presets=Presets"));
            var USER_BRUSHS_FOLDER =  new Folder( USER_PRESETS_FOLDER+"/Brushes" );
            if(USER_BRUSHS_FOLDER.exists){
                var brushFiles = USER_BRUSHS_FOLDER.getFiles('*.abr');
                for(var b = 0; b < brushFiles.length; b++ ) {
                    app.load( brushFiles[b] );
                }
            }
            // app root does need admin rights to write files
            var APP_BRUSHES_FOLDER = new Folder(app.path+'/Presets/Brushes');
            var brushFiles = APP_BRUSHES_FOLDER.getFiles('*.abr');
            for(var b = 0; b < brushFiles.length; b++ ) {
                    app.load( brushFiles[b] );
            }
            
            • 3. Re: Load all brushes in brush preset folder at startup
              crydrk Level 1

              Great! Thanks for the help, this works. Specifically the bottom 5 lines of your code is exactly what I needed Michael.

               

              A couple other questions. Is there a way to have the script unload brushes each time and then reload them? In case a brush is deleted or renamed for some kind of cleanup situation. Also, while beggars can't be choosers, loading this into the startup scripts on 50 users might be kind of tough. Is there a way that I could have a script run from our batch script launcher that would automatically set the script to run on startup? Or perhaps there is a file holding the data of which scripts to run on startup that I could have overwritten on startup?

               

              [edit] So I've noticed when I go to my preset manager a new instance of the loaded abr file is created each time. Is there a way to avoid this? Maybe the idea above about resetting to default each time might solve the problem.

              • 4. Re: Load all brushes in brush preset folder at startup
                Michael L Hale Level 5

                app.load will append the brushes. You can use scriptlistener to replace the brushes but that only works with one abr file.

                 

                There is a Photoshop startup script folder that contains script to be run when Photoshop starts. But unless all 50 users are on one machine I don't see any advantage to using that folder over Script Event Manager. Javascript runs in the host app so Photoshop has to be running for a Photoshop script. You might be able to do something with vbs that would work with a bat script.

                 

                It is very hard to work with presets like brushes, patterns, etc in scripting because there is not much direct access even with scriptlistener.

                • 5. Re: Load all brushes in brush preset folder at startup
                  crydrk Level 1

                  The startup folder would be perfect as when users run the launch script, we localize certain folders for things like brushes. We can localize this folder as well. I'll take a look for this. Is it just a folder called startup?

                   

                  Under the preset manager in the small button near 'Done' there is an option called 'Reset Brushes'. This would be absolutely perfect if there was some kind of equivalent command I could have happen before loading the brushes. I did a search for it in the documentation I found in the program files. No luck. I don't think I have a full documentation with every command. And google seems to return the documents I already have. Maybe I'm overlooking something?

                  • 6. Re: Load all brushes in brush preset folder at startup
                    Michael L Hale Level 5

                    You can use scriptlistener to run the 'Reset Brushes' command. The function below with reset the brushes with the Photoshop defaults.

                    function resetDefaultBrushes() {
                        var desc = new ActionDescriptor();
                            var ref = new ActionReference();
                            ref.putProperty( charIDToTypeID('Prpr'), charIDToTypeID('Brsh') );
                            ref.putEnumerated( charIDToTypeID('capp'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
                        desc.putReference( charIDToTypeID('null'), ref );
                        executeAction( charIDToTypeID('Rset'), desc, DialogModes.NO );
                    };
                    

                     

                    I am not sure of the Mac path but on Windows the Photoshop CS5 startup folder should be:

                     

                    var photoshopStartupFolder = new Folder(Folder.commonFiles+'/Adobe/Startup Scripts CS5/Adobe Photoshop');

                    • 7. Re: Load all brushes in brush preset folder at startup
                      crydrk Level 1

                      Cool, that function worked like a charm. The last piece of the puzzle will be to make this startup folder work. I wasn't quite sure where to do that code you posted for the folder. I ran the code as a script but it didn't seem to create folders or anything. I also tried building a new folder to that path and putting the startup script in there. Then I tried a combination of both thinking maybe 'photoshopStartupFolder' is some kind of global variable that needed to be set once. Again, no luck. Sorry if this is something obvious I appreciate your patience.

                      • 8. Re: Load all brushes in brush preset folder at startup
                        Michael L Hale Level 5

                        photoshopStartupFolder was just a reference to the start up folder. It should already exist on your system if Photoshop is installed and should contain a cross-dom script named 'photoshop.jsx'.

                         

                        So you don't need to create the folder. Just put whatever script you want to run at startup in there. I think that, unlike scripts run normally, startup script stay in memory while Photoshop is running so you will have to be careful that you don't have any name collisions.

                        • 9. Re: Load all brushes in brush preset folder at startup
                          crydrk Level 1

                          Hm... It seems what I am missing is where the file path for the startup folder is. I've done a search for "photoshop.jsx" on my C: drive but it can't find anything. I'm using CS5 if that makes a difference.

                           

                          Another angle I'm thinking of is that since we're launching from a batch script, maybe the launch photoshop command can include javascript? That way the script will just run when we run our launcher.