6 Replies Latest reply on Jun 11, 2015 7:50 AM by rafaeloz

    Automatic variable Change of the Place item on a action


      I'm begining in the scripting area, but I'm lost realy.  I looking in a way to change the place automatic based on the filename/ folder. Today I do like this:

      I'm aplying a image in the back of a photo with automate batch. My actions goes in resume like this.


      set the background - to unlock the layer

      Canvas size -to make the document matches the bigger image that will be the background

      place- That's where I have to change every folder with a especific background.




      in resume is this: I have files inside various folders , the name of the folder , is the name of the especific background that will aply to the images inside.


      Today I open a image, change the place ,close.  them I do the automate batch the folder with my action, because if I put the place to bring , it will make me to especify every in every image in the folder during action.

        • 1. Re: Automatic variable Change of the Place item on a action
          c.pfaffenbichler Level 9

          Sorry, but I don’t quite follow.

          Could you provide a sketch and/or screenshots to illustrate your intended workflow?

          • 3. Re: Automatic variable Change of the Place item on a action
            JJMack Most Valuable Participant

            I think I understand now. You want to process all the images in the KIT-01 Tree.

            Each sub folder has a folder name that is the name of a background image that resides in your MONTADAS background image folder that you want the images in the sub to have.


            I believe you can do that with a script for I have seen scripts that processes sub folder images. It basically a script that has two loop one nested in the other. The script need a dialog or prompt for the two folders. The Image tree folder and the Background image folder or these need to be hard coded folders. Also a output location would be a useful as a  dialog field or prompt. The names will be in URI format.


            The code would look something like the following which is not real code.


            for sub folders in image tree {

                  get sub folder name

                  for images in sub folder name {

                        open image

                        place background folder's image that has sub this sub folder name

                        save image in output location



            1 person found this helpful
            • 4. Re: Automatic variable Change of the Place item on a action
              rafaeloz Level 1

              OK, but you think that is possible? I really lost, but I'll consider that . Thanks .

              • 5. Re: Automatic variable Change of the Place item on a action
                JJMack Most Valuable Participant

                Lost soul... I'm just a hacker I don't realy know javascript. I'm a cut and past man a theif. A script that I know that can process all files in a tree in the image processor script that ships with Photoshop.  So I took a quick look at it. In it I saw a function named FindAllFiles. This  function returns an array of all files in a tree.  Each element contains a files full path name. So you can parse out the filename and the sub directory its in.  It should be easy loop through this array and do what you want.


                Here is a hack change the var tree to your image tree to see the array. I updated the hack to help you parse out the varables that you will need to do what you want.  Note that this function is recursive can handle a tree with many sub doirectory levels.  You show  a tree with only one lower sub folder level with no images in the tree root. This hack should help you see the posibilites. You  need to deside if you want a dialog,  prompts or hard code the three folders  to process the imput image tree, the background image folder and the output tree. 


                You would need to replace the alert code line with code to do what you want using the varable displayed in the alert.


                var tree = "C:/ImageTree";

                inputFiles = new Array();

                inputFiles = FindAllFiles( tree, inputFiles );



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

                     / Isolate File Part

                     var fullName = inputFiles[i];

                     var Name =  decodeURI(inputFiles[i]).replace(/\.[^\.]+$/, ''); // strip the extension off

                     var imagetreeroot = "";

                     imagetreeroot= Name.substr(0, Name.indexOf(tree) + tree.length +1); // stript the tree root off

                     Name = Name.substr(Name.indexOf(tree) + tree.length +1);

                     var imagePath = "";

                     while (Name.indexOf("/") != -1 ) { // strip the sub directories path off

                          imagePath= imagePath + Name.substr(0, Name.indexOf("/") + 1);

                          Name = Name.substr(Name.indexOf("/") + 1 ,);


                     var backgroundName = imagePath.substr(0, imagePath.length - 1); // Strip off traling "/"

                     while (backgroundName.indexOf("/") != -1 ) { // strip  the higher sub directories

                          backgroundName = backgroundName.substr(backgroundName.indexOf("/") + 1 ,);


                alert("Image File Path: "  + fullName

                     + "\rImage Tree Root: " + imagetreeroot

                     + "\rImage Sub Path: " + imagePath

                     + "\rImage File Name: " + Name

                     + "\rBackground Name: " + backgroundName );





                // Function: FindAllFiles

                // Usage: Find all the files in the given folder recursively

                // Input: srcFolder is a string to a folder

                //   destArray is an Array of File objects

                // Return: Array of File objects, same as destArray


                function FindAllFiles( srcFolderStr, destArray ) {

                var fileFolderArray = Folder( srcFolderStr ).getFiles();


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

                     var fileFoldObj = fileFolderArray[i];

                     if ( fileFoldObj instanceof File ) {

                               destArray.push( fileFoldObj );

                               } else { // folder

                                    FindAllFiles( fileFoldObj.toString(), destArray );



                return destArray;



                Message was edited by: JJMack

                • 6. Re: Automatic variable Change of the Place item on a action
                  rafaeloz Level 1

                  sorry for thank you so late

                  Really thank you