No internet connection
  1. Home
  2. How to

How to create folders

By Dario Ramaglia @dario.ramaglia
    2019-06-27 07:38:07.486Z

    Everytime I create a new session, I always create 1 folder inside the main session folder called "Others".
    Inside "Others" I then create "Misc" and "Old Cuts". I was wondering if there's a way to automate all of that.

    Solved in post #2, click to view
    • 9 replies
    1. Yes @dario.ramaglia there is :)

      Here's an example of creating this folder structure of the currently open session in PT:

      
      //Get the directory (folder) of the currently open PT session
      var sessionDir = sf.ui.proTools.mainWindow.sessionPath.split('/').slice(0, -1).join('/');
      
      //Create a sub-directory under the session folder, called "Others"
      sf.file.directoryCreate({
          path: sessionDir + '/Others'
      });
      
      //Create a sub-directory under the session folder's sub-directory "Others", called "Misc"
      sf.file.directoryCreate({
          path: sessionDir + '/Others/Misc'
      });
      
      //Create a sub-directory under the session folder's sub-directory "Others", called "Old Cuts"
      sf.file.directoryCreate({
          path: sessionDir + '/Others/Old Cuts'
      });
      
      //Open the "Others" sub-directory
      sf.appleScript.finder.open(sessionDir + '/Others');
      sf.ui.finder.appActivate();
      sf.ui.finder.windows.first.elementRaise();
      
      Reply1 LikeSolution
      1. Dario Ramaglia @dario.ramaglia
          2020-02-24 10:38:53.186Z

          I need a new little help :)
          What if I want SF to ask me how to name a folder?
          Let's say I want to create all the hierarchy of folders for my new project, I'd like SF to ask me for the name of the project so it cane rename the main folder accordingly.
          What do you think? A good idea?

          1. Use prompt and save the output into a variable, for example like this:

            var sessionName = prompt('What should we call your new session?');
            
            sf.file.directoryCreate({
                path: '~/Documents/My Pro Tools Sessions/' + sessionName + ''
            });
            
            1. Note for putting in variables inside strings like paths, you might want to use back-tick string syntax (string interpolation) instead, as it makes things a little clearer:

              var sessionName = prompt('What should we call your new session?');
              
              sf.file.directoryCreate({
                  path: `~/Documents/My Pro Tools Sessions/${sessionName}`
              });
              
              1. Dario Ramaglia @dario.ramaglia
                  2020-02-25 09:21:25.906Z

                  Last question, I swear.
                  Is it possible to create folder in the focused Finder window instead of a pre-defined folder?

                  1. Dario Ramaglia @dario.ramaglia
                      2020-02-25 09:40:04.926Z2020-02-25 10:07:07.145Z

                      This could be a solution.
                      I Just drug the folder on the second prompt ;)

                      var sessionName = prompt('What should I call your main project folder?');
                      
                      var pathName = prompt('Where should I put it?')
                      
                      sf.file.directoryCreate({
                          path: `${pathName}/${sessionName}`
                      });
                      
                      sf.file.directoryCreate({
                          path: `${pathName}/${sessionName}` + '/Folder1'
                      });
                      
                      sf.file.directoryCreate({
                          path: `${pathName}/${sessionName}` + '/Folder2'
                      });
                      
                      sf.file.directoryCreate({
                          path: `${pathName}/${sessionName}` + '/Folder1/SubFolder1'
                      });
                      
                      //Open the "Others" sub-directory
                      sf.appleScript.finder.open(`${pathName}/${sessionName}`);
                      sf.ui.finder.appActivate();
                      sf.ui.finder.windows.first.elementRaise();
                      1. In reply todario.ramaglia:

                        Hi @dario.ramaglia

                        You can get info about the open Finder window in a number of ways:

                        //To get the path to the first selected file:
                        var path = sf.ui.finder.firstSelectedPath;
                        
                        //To get the path to the open folder in the top most window:
                        var dirPath = sf.appleScript.finder.firstWindow.targetPath;
                        
                        1. This means in your case I'd probably do:

                          var sessionName = prompt('What should I call your main project folder?');
                          
                          var pathName = sf.appleScript.finder.firstWindow.targetPath;
                          
                          sf.file.directoryCreate({
                              path: `${pathName}/${sessionName}`
                          });
                          
                          sf.file.directoryCreate({
                              path: `${pathName}/${sessionName}` + '/Folder1'
                          });
                          
                          sf.file.directoryCreate({
                              path: `${pathName}/${sessionName}` + '/Folder2'
                          });
                          
                          sf.file.directoryCreate({
                              path: `${pathName}/${sessionName}` + '/Folder1/SubFolder1'
                          });
                          
                          //Open the "Others" sub-directory
                          sf.appleScript.finder.open(`${pathName}/${sessionName}`);
                          sf.ui.finder.appActivate();
                          sf.ui.finder.windows.first.elementRaise();
                          
              2. In reply todario.ramaglia:
                Chip Sloan @ChipSloan
                  2020-09-30 18:50:39.791Z

                  I've got a version of this working and am wondering it I can add a line of code to always create folders inside the session folder when a new session is created. I always create the same 3 subfolders in my sessions, Downloads, Mixes and Other. I would love to have those just auto create in every session and not have to devote a command or button to it.