No internet connection
  1. Home
  2. How to

Exporting clips as mp3 to a new folder

By Rostislav Supa @Rostislav_Supa
    2024-10-30 12:47:41.012Z

    Hi, is there a macro to select a 2nd item in any popup menu? The name of the item changes each time so it does not work with Action like Select Item in Popup Menu. Thank you

    • 19 replies

    There are 19 replies. Estimated reading time: 16 minutes

    1. Could you give an example of which popup menu(s) you're looking to select from?

      1. RRostislav Supa @Rostislav_Supa
          2024-10-31 08:17:58.474Z

          Hi Chris, thanks for replying. The popup menu is the one after Exporting Selected clips in PT and then choosing directory. Then a Finder window opens inside PT and here I'd like to select the second item in the popup menu. The idea is that it moves Finder Columns to left and I am then able to select a destination folder inside the project folder named -EXPORT. In other words: I'd like to Export Selected clips in PT to a destination folder which is always named -EXPORT and is always inside the project folder. Hope that makes sense:) Thank you for any input on this...

          1. Which version of Pro Tools are you using?

            1. RRostislav Supa @Rostislav_Supa
                2024-10-31 19:46:49.548Z

                I'm currently using PT Studio 2024.6.0

              • In reply toRostislav_Supa:
                Chris Shaw @Chris_Shaw2024-10-31 20:02:15.692Z2024-10-31 21:52:14.513Z

                You can easily export selected clips as files directly into your "-EXPORTS" folder using the new PT SDK commands in SF. The following will export the clips at their current sample rate / bit depth in the session.
                This script will also create the "-EXPORTS" folder in your session directory if it doesn't exist already.
                This runs on the more recent versions of PT.

                const destinationFolder = "-EXPORTS"
                const trackName = "PRINT"
                
                //Creat destination path
                sf.ui.proTools.appActivateMainWindow();
                
                let sessionPath = sf.app.proTools.getSessionPath().sessionPath;
                sessionPath = sessionPath.split(":").slice(0, -1).join("/").slice(1)
                
                let destinationPath = `${sessionPath}/${destinationFolder}`;
                
                // create destination folder
                sf.file.directoryCreate({ path: destinationPath })
                
                sf.app.proTools.selectAllClipsOnTrack({
                    trackName:trackName
                })
                
                sf.app.proTools.exportClipsAsFiles({
                    targetDirectory: destinationPath,
                    // duplicateNames:,
                    // bitDepth:,
                    // enforceAvidCompatibility:,
                    // fileType: ,
                    // format:,
                    // sampleRate:,
                })
                

                Lines 21-26 are commented but if you need to change the file format (or the other options) remove the "//" at the beginning of the line and hover your mouse over the property to see the available options:
                (Here I'm hovering over the fileType property:

                1. RRostislav Supa @Rostislav_Supa
                    2024-10-31 21:06:21.253Z

                    Thanks a lot, Chris! It works just great.
                    May I have one more question - I'd like to select all clips on a track called PRINT. When I create a macro for that it works fine. However when I convert it into a script it does not work. Here is the script that SF writes:

                    (throw 'context missing').selectAllClipsOnTrack({
                    trackName: "PRINT",
                    });

                    1. I edited the first script above so that it selects all of the clips on the "PRINT" track (line 15-17)

                      1. RRostislav Supa @Rostislav_Supa
                          2024-10-31 21:55:40.219Z

                          Amazing! Thanks

                      2. In reply toChris_Shaw:
                        Chris Shaw @Chris_Shaw2024-10-31 21:45:14.544Z2024-11-04 18:26:01.047Z

                        I realized that the script above won't export MP3s.
                        this should do it:

                        const destinationFolder = "-EXPORTS"
                        const mp3FolderName = "MP3 320"
                        
                        //Create destination path
                        sf.ui.proTools.appActivateMainWindow();
                        
                        let sessionPath = sf.app.proTools.getSessionPath().sessionPath;
                        sessionPath = sessionPath.split(":").slice(0, -1).join("/").slice(1)
                        
                        let destinationPath = `${sessionPath}/${destinationFolder}`;
                        
                        // create exports folder if neccessary
                        sf.file.directoryCreate({ path: destinationPath })
                        
                        //Create MP3 Folder if necessary
                        const mp3Path = `${destinationPath}/${mp3FolderName}`
                        sf.file.directoryCreate({ path: mp3Path })
                        
                        
                        //Open Export Clips
                        sf.keyboard.press({
                            keys: "cmd+shift+k",
                        });
                        
                        //Wait for Export Conf window
                        const exportWin = sf.ui.proTools.windows.whoseTitle.is("Export Selected").first;
                        
                        
                        
                        /// PUT YOUR CODE FOR SETTNG MP3 OPTIONS etc HERE
                        
                        
                        //Click "Export..."
                        exportWin.elementWaitFor();
                        
                        exportWin.buttons.whoseTitle.is("Choose...").first.elementClick();
                        
                        
                        // Navigate to "-EXPORTS" folder
                        const openDlg = sf.ui.proTools.windows.whoseTitle.is("Open").first;
                        openDlg.elementWaitFor();
                        
                        //Get a reference to the focused window in the frontmost app:
                        var win = sf.ui.frontmostApp.focusedWindow;
                        
                        //Open the Go to... sheet
                        sf.keyboard.type({ text: '/' });
                        
                        //Wait for the sheet to appear
                        win.sheets.first.elementWaitFor({ timeout: 500 }, 'Could not find "Go to" sheet in the Save/Open dialog').element;
                        
                        sf.keyboard.type({
                            text: mp3Path,
                        });
                        
                        // Close open file dialog
                        sf.keyboard.press({ keys: 'return' });
                        
                        win.sheets.first.elementWaitFor({ waitType: "Disappear" })
                        
                        // Close open file dialog
                        sf.keyboard.press({ keys: 'return' });
                        openDlg.elementWaitFor({ waitType: "Disappear" });
                        
                        //Click Export
                        exportWin.buttons.whoseTitle.is("Export...").first.elementClick();
                        exportWin.elementWaitFor({ waitType: "Disappear" })
                        
                        1. RRostislav Supa @Rostislav_Supa
                            2024-10-31 21:50:51.963Z

                            That's perfect, thank you!

                            1. In reply toChris_Shaw:
                              RRostislav Supa @Rostislav_Supa
                                2024-11-02 21:15:29.422Z

                                Hi Chris, sorry to bother but I'd like to ask one more following question. In this '-EPORTS' folder I'd like to create a subfolder named 'MP3 320' which will be a new destination folder. The idea is that I might export the clips again for example in mp3 128 and so another destination subfolder named 'MP3 128' will be created etc. For each format I'll duplicate the code and dedicate a separate trigger. Is there a way that the script creates the first folder just once and then only destination subfolders? Thank you

                                1. If the -EXPORTS folder already exists then the script won't try to create it.

                                  1. Chris Shaw @Chris_Shaw2024-11-04 18:26:51.090Z2024-11-04 18:53:35.505Z

                                    I've edited the MP3 code above. Just change the name of the MP3 folder to whatever you'd like. It will create it in the "-EXPORTS" directory if it doesn't exist already.

                                    1. RRostislav Supa @Rostislav_Supa
                                        2024-11-05 15:57:26.287Z

                                        Hi Chris, that's great, thank you! It creates both folders, however the files are exported still into the -EXPORTS not he MP3 folder. I have tried to tweak that but no success:) Thank you for you time and input in this...

                                        1. Seems to be working here with no issues.
                                          Could you post your script here so I can check it out?

                                          1. RRostislav Supa @Rostislav_Supa
                                              2024-11-06 19:36:17.580Z
                                              const destinationFolder = "-EXPORTS"
                                              const mp3FolderName = "MP3 128"
                                              const trackName = "MIX"
                                              
                                              //Create destination path
                                              sf.ui.proTools.appActivateMainWindow();
                                              
                                              let sessionPath = sf.app.proTools.getSessionPath().sessionPath;
                                              sessionPath = sessionPath.split(":").slice(0, -1).join("/").slice(1)
                                              
                                              let destinationPath = `${sessionPath}/${destinationFolder}`;
                                              
                                              
                                              // create destination folder
                                              sf.file.directoryCreate({ path: destinationPath })
                                              
                                              
                                              
                                              //Create MP3 Folder if necessary
                                              const mp3Path = `${destinationPath}/${mp3FolderName}`
                                              sf.file.directoryCreate({ path: mp3Path })
                                              
                                              
                                              
                                              sf.app.proTools.selectAllClipsOnTrack({
                                                  trackName:trackName
                                              })
                                              
                                              //Open Export Clips
                                              sf.keyboard.press({
                                                  keys: "cmd+shift+k",
                                              });
                                              
                                              //Wait for Export Conf window
                                              const exportWin = sf.ui.proTools.windows.whoseTitle.is("Export Selected").first;
                                              
                                              
                                              
                                              /// PUT YOUR CODE FOR SETTNG MP3 OPTIONS etc HERE
                                              sf.ui.proTools.windows.whoseTitle.is("Export Selected").first.popupButtons.allItems[3].popupMenuSelect({
                                                  menuPath: ["MP3"],
                                              });
                                              
                                              sf.ui.proTools.windows.whoseTitle.is("Export Selected").first.popupButtons.allItems[2].popupMenuSelect({
                                                  menuPath: ["Interleaved"],
                                              });
                                              
                                              sf.ui.proTools.windows.whoseTitle.is("Export Selected").first.popupButtons.first.popupMenuSelect({
                                                  menuPath: ["44.1 kHz"],
                                              });
                                              
                                              
                                              //Click "Export..."
                                              exportWin.elementWaitFor();
                                              
                                              exportWin.buttons.whoseTitle.is("Choose...").first.elementClick();
                                              
                                              
                                              // Navigate to "-EXPORTS" folder
                                              const openDlg = sf.ui.proTools.windows.whoseTitle.is("Open").first;
                                              openDlg.elementWaitFor();
                                              
                                              //Get a reference to the focused window in the frontmost app:
                                              var win = sf.ui.frontmostApp.focusedWindow;
                                              
                                              //Open the Go to... sheet
                                              sf.keyboard.type({ text: '/' });
                                              
                                              //Wait for the sheet to appear
                                              win.sheets.first.elementWaitFor({ timeout: 500 }, 'Could not find "Go to" sheet in the Save/Open dialog').element;
                                              
                                              sf.keyboard.type({
                                                  text: destinationPath,
                                              });
                                              
                                              // Close open file dialog
                                              sf.keyboard.press({ keys: 'return' });
                                              
                                              win.sheets.first.elementWaitFor({ waitType: "Disappear" })
                                              
                                              // Close open file dialog
                                              sf.keyboard.press({ keys: 'return' });
                                              openDlg.elementWaitFor({ waitType: "Disappear" });
                                              
                                              //Click Export
                                              exportWin.buttons.whoseTitle.is("Export...").first.elementClick();
                                              //exportWin.elementWaitFor({ waitType: "Disappear" })
                                              
                                              
                                              sf.wait({
                                                  intervalMs: 500,
                                              });
                                              
                                              sf.ui.proTools.windows.whoseTitle.is("MP3").first.elementWaitFor();
                                              
                                              sf.ui.proTools.windows.whoseTitle.is("MP3").first.popupButtons.allItems[3].popupMenuSelect({
                                                  menuPath: ["Highest Quality, Slower Encoding Time"],
                                              });
                                              
                                              sf.ui.proTools.windows.whoseTitle.is("MP3").first.popupButtons.allItems[2].popupMenuSelect({
                                                  menuPath: ["128kbit/s (44100Hz)"],
                                              });
                                              
                                              sf.ui.proTools.windows.whoseTitle.is("MP3").first.buttons.whoseTitle.is("OK").first.elementClick();
                                              
                                              
                                              preformatted text
                                              
                                              1. In reply toChris_Shaw:
                                                RRostislav Supa @Rostislav_Supa
                                                  2024-11-06 21:43:13.278Z

                                                  Thanks a lot, Chris

                                                  1. My bad - set the file path for theMP3 export to the EXPORTS folder instead of the MP3 folder.
                                                    I've edited the code a a little more to make it more concise and readable as well:

                                                    const destinationFolder = "-EXPORTS"
                                                    const mp3FolderName = "MP3 128"
                                                    const trackName = "MIX"
                                                    
                                                    //Create destination path
                                                    sf.ui.proTools.appActivateMainWindow();
                                                    
                                                    let sessionPath = sf.app.proTools.getSessionPath().sessionPath;
                                                    sessionPath = sessionPath.split(":").slice(0, -1).join("/").slice(1)
                                                    
                                                    let destinationPath = `${sessionPath}/${destinationFolder}`;
                                                    
                                                    // create destination folder if necessary
                                                    sf.file.directoryCreate({ path: destinationPath })
                                                    
                                                    //Create MP3 Folder if necessary
                                                    const mp3Path = `${destinationPath}/${mp3FolderName}`
                                                    sf.file.directoryCreate({ path: mp3Path })
                                                    
                                                    sf.app.proTools.selectAllClipsOnTrack({
                                                        trackName:trackName
                                                    })
                                                    
                                                    //Open Export Clips
                                                    sf.keyboard.press({
                                                        keys: "cmd+shift+k",
                                                    });
                                                    
                                                    //Wait for Export Conf window
                                                    const exportWindow = sf.ui.proTools.windows.whoseTitle.is("Export Selected").first;
                                                    
                                                    /// PUT YOUR CODE FOR SETTNG MP3 OPTIONS etc HERE
                                                    exportWindow.popupButtons.allItems[3].popupMenuSelect({
                                                        menuPath: ["MP3"],
                                                    });
                                                    
                                                    exportWindow.popupButtons.allItems[2].popupMenuSelect({
                                                        menuPath: ["Interleaved"],
                                                    });
                                                    
                                                    exportWindow.popupButtons.first.popupMenuSelect({
                                                        menuPath: ["44.1 kHz"],
                                                    });
                                                    
                                                    
                                                    //Click "Export..."
                                                    exportWindow.elementWaitFor();
                                                    
                                                    exportWindow.buttons.whoseTitle.is("Choose...").first.elementClick();
                                                    
                                                    
                                                    // Navigate to "-EXPORTS" folder
                                                    const openDlg = sf.ui.proTools.windows.whoseTitle.is("Open").first;
                                                    openDlg.elementWaitFor();
                                                    
                                                    //Get a reference to the focused window in the frontmost app:
                                                    var win = sf.ui.frontmostApp.focusedWindow;
                                                    
                                                    //Open the Go to... sheet
                                                    sf.keyboard.type({ text: '/' });
                                                    
                                                    //Wait for the sheet to appear
                                                    win.sheets.first.elementWaitFor({ timeout: 500 }, 'Could not find "Go to" sheet in the Save/Open dialog').element;
                                                    
                                                    sf.keyboard.type({
                                                        text: mp3Path,
                                                    });
                                                    
                                                    // Close open file dialog
                                                    sf.keyboard.press({ keys: 'return' });
                                                    
                                                    win.sheets.first.elementWaitFor({ waitType: "Disappear" })
                                                    
                                                    // Close open file dialog
                                                    sf.keyboard.press({ keys: 'return' });
                                                    openDlg.elementWaitFor({ waitType: "Disappear" });
                                                    
                                                    //Click Export
                                                    exportWindow.buttons.whoseTitle.is("Export...").first.elementClick();
                                                    //exportWin.elementWaitFor({ waitType: "Disappear" })
                                                    
                                                    sf.wait({
                                                        intervalMs: 500,
                                                    });
                                                    
                                                    const mp3Window = sf.ui.proTools.windows.whoseTitle.is("MP3").first;
                                                    
                                                    mp3Window.elementWaitFor();
                                                    
                                                    mp3Window.popupButtons.allItems[3].popupMenuSelect({
                                                        menuPath: ["Highest Quality, Slower Encoding Time"],
                                                    });
                                                    
                                                    mp3Window.popupButtons.allItems[2].popupMenuSelect({
                                                        menuPath: ["128kbit/s (44100Hz)"],
                                                    });
                                                    
                                                    mp3Window.buttons.whoseTitle.is("OK").first.elementClick();
                                                    
                                                    1. RRostislav Supa @Rostislav_Supa
                                                        2024-11-07 11:22:43.747Z

                                                        Chris, this is awesome! It works perfectly. Thank you so so much for your time. This saves me a lot of clicks:)