6 Replies Latest reply on Aug 27, 2016 5:17 PM by Chuck Uebele

    Repeat action and save file

    anton.bohlin

      Hello,

       

      I'm having a fever and trying to accomplish something that seems very simple without knowing anything about scripting.

       

      I've made an action that applies some simple effects (blur, threshold and high pass). What I want to do is to repeat the action for n times and save an incremental png for each repetition so that I end up with a numbered file sequence of the action being applied more and more ( like in this example Photoshop Cs5 Filters Animation on Vimeo).

       

      After som googling I ended up using AppleScript and was able to repeat the action for as many times as I want, but I'm completely stuck on the file saving part. This is what I have at the moment:

       

      Any help is greatly appreciated!

       

      tell application "Adobe Photoshop CC 2015.5"

           set StartingPoint to current document

           set theFilePath to file path of current document

       

                repeat with n from 1 to 10

                     set myFile to theFilePath & ":output:image" & {n as string} & ".png"

                     do action "CrazyAction" from "Default Actions"

                     save current document in file myFile as PNG with options {class:PNG save options, interlaced:false}

                end repeat

       

      end tell

       

      In case someone comes up with the solution I also have another related question: how can I make sure the output file names will have some padding in the number? Ideally I'd end up with image001.png, image002.png and so on rather than image1.png, image2.png.

       

      Many thanks in advance!

        • 1. Re: Repeat action and save file
          Chuck Uebele Adobe Community Professional & MVP

          If you don't know much about scripting, I would use javascript rather than applescript, as it's cross platform and most people here on the forum know javascript better or only - like me - and can then help you. Saving a file in javascript, and i'm assuming applescript boils down to setting up a variable for the file name and doing a saveas, incriminating the file name by some number in a loop.

          • 2. Re: Repeat action and save file
            anton.bohlin Level 1

            Thanks for the reply, maybe that's my solution but I'd have no idea how to script that. To me the AppleScript syntax seemed like a much more friendly approach for a complete beginner.

            • 3. Re: Repeat action and save file
              anton.bohlin Level 1

              Would anybody be able to help me script this using JavaScript or other popular script language? I feel like it should be pretty simple to achieve.

               

              To a currently open document in Photoshop

              repeat n times:

                   Trigger my action

                   Save an incrementally named image

               

              So that I end up with an image sequence where the action has been applied again as many times as there are images.

               

              Thanks

              • 4. Re: Repeat action and save file
                Chuck Uebele Adobe Community Professional & MVP

                One of the things you can do with javascript that you can't do with applescript is to use the scriptlistener plugin. This plugin is put into the photoshop plugins folder, and when it's there (you don't want to leave it there all the time) it will record pretty much everything you do, much like an action, but it will generate code to a log file on your desktop. I used it for recording running an action and for saving the png. Those parts of the code are in the functions in the script. So I just established a base folder name, a base file name, and a starting counter. The script will then run your action and save a png to that base folder and change the base file name by the counter increasing by one each time. You need to put in the name of your action and the name of the action set into the script.

                 

                #target photoshop
                var fileName = 'myFile-';
                var folderPath = new Folder (Folder.desktop +'/action test/')//create whatever path you want here. Make sure the folder exists!
                var doc = activeDocument;
                var counter = 1//counter for changing the filename
                
                for (var i=0;i<4;i++){//Change number 4 to whatever number you want it to repeat + 1
                    runMyAction ("twirl", "Chuck");//put in action name and action set name. This line can be duplicated for different actions.
                    savePNG ()
                    counter++
                    }
                
                
                function runMyAction(myAction, myActionSet){
                    var idPly = charIDToTypeID( "Ply " );
                        var desc25 = new ActionDescriptor();
                        var idnull = charIDToTypeID( "null" );
                            var ref8 = new ActionReference();
                            var idActn = charIDToTypeID( "Actn" );
                            ref8.putName( idActn, myAction );//changed to a variable
                            var idASet = charIDToTypeID( "ASet" );
                            ref8.putName( idASet, myActionSet );//Changed to a variable
                        desc25.putReference( idnull, ref8 );
                    executeAction( idPly, desc25, DialogModes.NO );
                    }
                
                function savePNG(){
                    var idsave = charIDToTypeID( "save" );
                        var desc28 = new ActionDescriptor();
                        var idAs = charIDToTypeID( "As  " );
                            var desc29 = new ActionDescriptor();
                            var idPGIT = charIDToTypeID( "PGIT" );
                            var idPGIT = charIDToTypeID( "PGIT" );
                            var idPGIN = charIDToTypeID( "PGIN" );
                            desc29.putEnumerated( idPGIT, idPGIT, idPGIN );
                            var idPNGf = charIDToTypeID( "PNGf" );
                            var idPNGf = charIDToTypeID( "PNGf" );
                            var idPGAd = charIDToTypeID( "PGAd" );
                            desc29.putEnumerated( idPNGf, idPNGf, idPGAd );
                            var idCmpr = charIDToTypeID( "Cmpr" );
                            desc29.putInteger( idCmpr, 9 );
                        var idPNGF = charIDToTypeID( "PNGF" );
                        desc28.putObject( idAs, idPNGF, desc29 );
                        var idIn = charIDToTypeID( "In  " );
                        desc28.putPath( idIn, new File( folderPath + '/'+ fileName + counter+ ".png" ) );//set folder path and name
                        var idDocI = charIDToTypeID( "DocI" );
                        desc28.putInteger( idDocI, 200 );
                        var idCpy = charIDToTypeID( "Cpy " );
                        desc28.putBoolean( idCpy, true );
                        var idsaveStage = stringIDToTypeID( "saveStage" );
                        var idsaveStageType = stringIDToTypeID( "saveStageType" );
                        var idsaveBegin = stringIDToTypeID( "saveBegin" );
                        desc28.putEnumerated( idsaveStage, idsaveStageType, idsaveBegin );
                    executeAction( idsave, desc28, DialogModes.NO );
                    }
                
                • 5. Re: Repeat action and save file
                  anton.bohlin Level 1

                  Thank you Chuck! Works beautifully, and very nice tip about the scriptlistener plugin!

                  • 6. Re: Repeat action and save file
                    Chuck Uebele Adobe Community Professional & MVP

                    Yea, some things you can't script without using the scriptlistener, so I'm not sure how people who use applescript code that type of stuff.