Import audiofiles from selected Finder folder and spot each audio fIle to original timestamp
Hey,
I need help with a script that can combine a number of activities:
Select a Folder (Finder)
Import all Audiofiles from that folder into Protools via import audio
Spot each Audiofile to his orginal time stamp on a new track
Perhaps there is a script that performs similar skripts that can help me get it running. Or even a comination of markos...
Thanks!
best,
Holger
- MMatt Friedman @Matt_Friedman
2 years later, try this (requires at least SF 5.7 and PT 2023.6/2023.9)
Select a folder full of audio files in Finder, and run this.
It will import these files into an already open session, on to new tracks, then it will spot the clips on each track to their original time stamp.
function importAudioFiles(path, format = "wav", handling = "AddAudio", location = "SessionStart") { const audioFiles = sf.file.directoryGetFiles({ path: path, searchPattern: "*." + format.toLowerCase(), }).paths; if (audioFiles === undefined || !audioFiles.length) throw 'There are no Audio files'; sf.ui.proTools.appActivate(); sf.ui.proTools.appActivateMainWindow(); sf.app.proTools.importAudio({ sourcePaths: audioFiles, audioFileHandling: handling, location: location, destination: "NewTrack", spotLocationType: "Start", spotLocationValue: "", spotLocationOffset: "TimeCode", }, "Import of audio files failed.") } function spotClipToOriginalTimestamp() { sf.keyboard.press({ keys: "alt+f", }); var menu = sf.ui.proTools.clipOpenContextMenu().popupMenu; menu.menuClickPopupMenu({ menuPath: ['Spot...'], }); sf.ui.proTools.clipSpotDialog.elementWaitFor(); //hack to make sure everything loads sf.ui.proTools.clipSpotDialog.invalidate().buttons.whoseTitle.is("OK").first.elementWaitFor(); const currentStart = () => sf.ui.proTools.clipSpotDialog.textFields.first.value.invalidate().value; const originalTimeStamp = () => sf.ui.proTools.clipSpotDialog.children.whoseRole.is("AXStaticText").allItems[7].value.invalidate().value.split(".")[0]; if (originalTimeStamp() != currentStart()) { while (originalTimeStamp() != currentStart()) { sf.ui.proTools.clipSpotDialog.mouseClickElement({ relativePosition: { x: 274, y: 256 } }) sf.wait({ intervalMs: 100 }) } sf.ui.proTools.clipSpotDialog.buttons.whoseTitle.is("OK").first.elementClick(); } else { sf.ui.proTools.clipSpotDialog.buttons.whoseTitle.is("Cancel").first.elementClick(); } sf.ui.proTools.clipSpotDialog.elementWaitFor({ waitForNoElement: true }) } function main() { importAudioFiles(sf.ui.finder.firstSelectedPath) sf.ui.proTools.selectedTracks.invalidate().trackHeaders.slice().map(track => { track.trackSelect(); sf.ui.proTools.clipDoForEachClipInTrack({ action: spotClipToOriginalTimestamp }) }); } main();
- DDave Weingarten @Dave_Weingarten
This is really cool. What would be the best way to skip the spot to timestamp portion? I'd love to just import to session start. Thank you.
- MMatt Friedman @Matt_Friedman
function importAudioFiles(path, format = "wav", handling = "AddAudio", location = "SessionStart") { const audioFiles = sf.file.directoryGetFiles({ path: path, searchPattern: "*." + format.toLowerCase(), }).paths; if (audioFiles === undefined || !audioFiles.length) throw 'There are no Audio files'; sf.ui.proTools.appActivate(); sf.ui.proTools.appActivateMainWindow(); sf.app.proTools.importAudio({ sourcePaths: audioFiles, audioFileHandling: handling, location: location, destination: "NewTrack", spotLocationType: "Start", spotLocationValue: "", spotLocationOffset: "TimeCode", }, "Import of audio files failed.") } importAudioFiles(sf.ui.finder.firstSelectedPath);
- DDave Weingarten @Dave_Weingarten
Yessss thank you so much Matt. This is amazing.
- In reply toMatt_Friedman⬆:DDave Weingarten @Dave_Weingarten
Hey Matt, I've run into an issue where the incoming files are not being converted to the session sample rate... Any ideas why that could be? Thanks again.
- MMatt Friedman @Matt_Friedman
This would be the doc block for the function, which may be helpful to you
/** * Import Audio Files * * @param {string} path * @param {"WAV" | "AIFF"} format * @param {"AddAudio" | "CopyAudio" | "ConvertAudio" | "Default"} handling * @param {"SessionStart" | "SongStart" | "Selection" | "Spot" | "None"} location */
So you could try using
"Default"
for thehandling
variable, like:importAudioFiles(sf.ui.finder.firstSelectedPath, "WAV", "Default", "SessionStart");
Alternatively, you can also just switch the default value to
"Default"
by changing the function definition to:/** * Import Audio Files * * @param {string} path * @param {"WAV" | "AIFF"} format * @param {"AddAudio" | "CopyAudio" | "ConvertAudio" | "Default"} handling * @param {"SessionStart" | "SongStart" | "Selection" | "Spot" | "None"} location */ function importAudioFiles(path, format = "wav", handling = "Default", location = "SessionStart") { const audioFiles = sf.file.directoryGetFiles({ path: path, searchPattern: "*." + format.toLowerCase(), }).paths; if (audioFiles === undefined || !audioFiles.length) throw 'There are no Audio files'; sf.ui.proTools.appActivate(); sf.ui.proTools.appActivateMainWindow(); sf.app.proTools.importAudio({ sourcePaths: audioFiles, audioFileHandling: handling, location: location, destination: "NewTrack", spotLocationType: "Start", spotLocationValue: "", spotLocationOffset: "TimeCode", }, "Import of audio files failed.") } importAudioFiles(sf.ui.finder.firstSelectedPath);