6 Replies Latest reply on Jun 22, 2015 11:04 AM by spdorsey6969

    Creating a folder in Finder/Windows using a PS action

    spdorsey6969 Level 1

      I need to build a folder hierarchy on the Desktop and place files in it using a Photoshop action. for instance:

       

      Master Folder Name

      - High Res

      -- HR_filename.jpg

      -- HR_filename.png

      - Low Res

      -- LR_filename.jpg

      -- LR_filename.png

      - Master

      -- master filename.psb

       

      Using javascript (so that it's portable between Mac and Windows), is there an simple way do accomplish this? Perhaps a tutorial? I'm having a hard time finding good info in the forums - it keeps asking me to start a new post.

       

      Thanks

        • 1. Re: Creating a folder in Finder/Windows using a PS action
          spdorsey6969 Level 1

          I found this script that works and does a lot of what I need. Is there a way to make the folder name "Folder A" inherit the file's name without the extension?

           

          I also need to figure out how to save specific file types into those specific folders after the master folder has been named.

           

          Re: Create folder hierarchy

           

          var target = Folder.selectDialog("Choose a target folder"); 

          if(!(Folder(target+"/"+"filename")).exists) 

                  new Folder(target + "/" + "filename").create();

                  new Folder(target + "/" + "filename" + "/hi-res").create();

                  new Folder(target + "/" + "filename" + "/lo-res").create();

                  new Folder(target + "/" + "filename" + "/master").create();

              }

          • 2. Re: Creating a folder in Finder/Windows using a PS action
            michelr31372089 Level 2

            Can you try this ?

             

            [Code]

            var folderPath = new Array();

            folderPath[0] = "~/DeskTop/High%20Res";

            folderPath[1] = "~/DeskTop/High%20Res/HR_filename.jpg";

            folderPath[2] = "~/DeskTop/High%20Res/HR_filename.png";

            folderPath[3] = "~/DeskTop/Low%20Res";

            folderPath[4] = "~/DeskTop/Low%20Res/LR_filename.jpg";

            folderPath[5] = "~/DeskTop/Low%20Res/LR_filename.png";

            folderPath[6] = "~/DeskTop/Master";

            folderPath[7] = "~/DeskTop/Master/master%20filename.psb";

             

            for (var i=0;i<8;i++)

            {

                createFolder(folderPath[i] );

            }

            alert("Done !");

             

            function createFolder(folderPath)

            {

                var folder = Folder(folderPath);

                if (!folder.exists) folder.create();

                return;

            }

            [/Code]

            • 3. Re: Creating a folder in Finder/Windows using a PS action
              spdorsey6969 Level 1

              That pretty much does what my script does. It names a hierarchy of folders.


              I need the master folder (~/DeskTop/High%20Res) to inherit the name of the document that is currently frontmost in Photoshop.

              • 4. Re: Creating a folder in Finder/Windows using a PS action
                Chuck Uebele Adobe Community Professional & MVP

                Define the folder you want to rename:

                var renamedFolder = new Folder('/c/theFolder/')

                get your file name and strip off the extension. then:

                 

                renamedFolder.rename(fileName);

                if that folder is being used by another program, it will not rename it, so check that it does change with the folder.exists command.

                • 5. Re: Creating a folder in Finder/Windows using a PS action
                  michelr31372089 Level 2

                  Sorry, I am not sure to have understood because of my terrible English.

                   

                  In the following code, you have to define High Res ( > 92 pixels per inch for instance).

                  [Code]

                  // MAC Finder ou WINDOWS Explorer, on autorise le double clic  et on fait passer Photoshop au 1er plan

                  #target photoshop

                  app.bringToFront();

                   

                  var lowDef = 91; // 92 ppi = high Resolution (for example)

                  var file = app.activeDocument;

                  var master = file.name.substring( 0, file.name.indexOf(".") );

                  var extension = file.name.substring(file.name.lastIndexOf("."));

                   

                  var highRes=false;

                  var resolution = file.resolution;

                  if (resolution>lowDef) highRes=true;

                  file = file.name;

                   

                  var folder = new Array();

                  folder[0] = "~DeskTop/"+master;

                  if (highRes)

                  {

                      folder[1] = "~DeskTop/"+master+"/High%20Res/";

                      folder[2] = folder[1]+"/HR_"+master+extension;

                  }

                  else

                  {

                      folder[1] = "~DeskTop/"+master+"/Low%20Res/";

                      folder[2] = folder[1]+"/LR_"+master+extension;

                  }

                  alert("Done !");

                   

                  for (var i=0;i<3;i++)

                  {

                      createFolder(folder[i] );

                  }

                   

                  function createFolder(deskTopFolder)

                  {

                      var folder = Folder(deskTopFolder);

                      if (!folder.exists) folder.create();

                  }

                  [/Code]

                  • 6. Re: Creating a folder in Finder/Windows using a PS action
                    spdorsey6969 Level 1

                    Apparently, this works:

                     

                    var target = Folder.selectDialog("Choose a target folder");  

                     

                    var docname = app.activeDocument.name.substring(0, app.activeDocument.name.indexOf('.'));

                     

                    if(!(Folder(target+"/"+"filename")).exists)   

                    {   

                            new Folder(target + "/" + docname).create(); 

                            new Folder(target + "/" + docname + "/hi-res").create();

                            new Folder(target + "/" + docname + "/lo-res").create();

                            new Folder(target + "/" + docname + "/simplified").create();

                        }