Exporting clips as mp3 to a new folder
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
- Chris Shaw @Chris_Shaw2024-10-30 20:04:52.487Z
Could you give an example of which popup menu(s) you're looking to select from?
- RRostislav Supa @Rostislav_Supa
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...
Chris Shaw @Chris_Shaw2024-10-31 18:57:31.468Z
Which version of Pro Tools are you using?
- RRostislav Supa @Rostislav_Supa
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 thefileType
property:- RRostislav Supa @Rostislav_Supa
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",
});Chris Shaw @Chris_Shaw2024-10-31 21:53:23.392Z
I edited the first script above so that it selects all of the clips on the "PRINT" track (line 15-17)
- RRostislav Supa @Rostislav_Supa
Amazing! Thanks
- 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" })
- RRostislav Supa @Rostislav_Supa
That's perfect, thank you!
- In reply toChris_Shaw⬆:RRostislav Supa @Rostislav_Supa
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
Chris Shaw @Chris_Shaw2024-11-04 18:21:48.622Z
If the -EXPORTS folder already exists then the script won't try to create it.
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.
- RRostislav Supa @Rostislav_Supa
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...
Chris Shaw @Chris_Shaw2024-11-05 19:27:47.320Z
Seems to be working here with no issues.
Could you post your script here so I can check it out?- RRostislav Supa @Rostislav_Supa
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
Chris Shaw @Chris_Shaw2024-11-06 23:33:33.082Z
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();
- RRostislav Supa @Rostislav_Supa
Chris, this is awesome! It works perfectly. Thank you so so much for your time. This saves me a lot of clicks:)