Hello! I'm trying to open a file from the Project Path and check if it exists and if not (show a message saying that the files doesn't exists) and ask the user for the correct path and open it. Any thoughts? I think it's very easy, but I'm still learning the code ;) Thank you!
- Christian Scheuer @chrscheuer2020-05-02 16:15:04.975Z
Hi Khonnor
Can you elaborate on what you mean by opening a file from the project path? And opening it how? Is this a txt file or something that should exist in the same directory as the open Pro Tools session?
Khonnor Wallace @Khonnor_Wallace
Thanks for the answer Christian! A txt, excel or html file that exists in the same directory as the open PT Session.
Christian Scheuer @chrscheuer2020-05-02 16:32:39.156Z
Something like this should get you going:
var projectDir = sf.ui.proTools.mainWindow.sessionPath.split('/').slice(0, -1).join('/'); var filePath = `${projectDir}/notes.txt`; if (!sf.file.exists({ path: filePath }).exists) { //The file doesn't exist. Ask the user filePath = sf.interaction.selectFile({ defaultLocation: projectDir, prompt: 'Please select a file to open', }).path; } sf.file.open({ path: filePath });
Khonnor Wallace @Khonnor_Wallace
Awesome Christian!! Thanks a lot! ;)
- In reply toKhonnor_Wallace⬆:Chris Shaw @Chris_Shaw2020-05-21 17:05:09.380Z
I'd like a script that does something similar to this one.
It would search the PT session path for a file that ends with "BU" (a Synchronize! X setup document). If it doesn't find one, then it would move up to the parent directory, search there, until it reaches the main directory of the drive. If it reaches the top level of the drive then the backup file doesn't exist so it will just open my backup program - Synchronize! X
Chris Shaw @Chris_Shaw2020-05-21 17:16:59.782Z2020-05-21 21:02:06.111Z
Here's a screen shot to explain a bit better. I'm mixing a song called Becca Bell for an album project by an artist named Judson McKinney. There is no file ending with "BU" in the session folder so I'd want SF to move up one directory to BECCA BELL 5.13.2020. The backup doc doesn't exist there either,. SF moves up one more directory (Justin McKinney) and there is the document ending with "BU". SF opens it and I can start the backup. If it didn't exist there SF would move up one more directory then be in the root directory of "Work Drive" where no "BU" document exists which then would trigger SF to open up my backup program Synchronize! X
I've tried to work it out myself but it seems above my expertise…
Thanks
Andrew Scheps @Andrew_Scheps
Hi Chris,
I'm actually working on this for you because I think it would be a very cool script to have. I'm a couple of steps away from having it but I had a question for you. Would it be better to search for files with the correct file extension (I think in this case it's .syncprox) so that there can't be false positives? Would you ever have other sync X files in the directories? Otherwise it might be better to come up with a more robust naming scheme for these files.
- In reply toChris_Shaw⬆:
Andrew Scheps @Andrew_Scheps
Ok, here's a script that does what you want, but instead of looking for part of a filename (which as I said above doesn't seem very robust) this searches for a filename extension which is defined as a constant at the top of the script so you can change it if you want (make sure to leave the period off the beginning of the extension). It the searches recursively from the session directory up to the root directory of the drive and if it still can't find a file it will ask you to find one (thanks Christian).
Only real limitation of the script is that if there is a directory with two files with the same extension it will open the first one alphabetically.
//The file extension for saved sync files const extension = 'syncprox' // This sets the search directory to the current session folder var sessionDir = sf.ui.proTools.mainWindow.sessionPath; var searchDir = '' var directoryDepth = sessionDir.split('/').length - 1 //how deep in the file structure are we, then adjust to keep from going up past the root of the drive var level, index, value, filePath; for (level = 1; level < directoryDepth; level++) { searchDir = sessionDir.split('/').slice(0, -level).join('/') let entries = sf.file.directoryGetEntries({ path: searchDir, includeDirectories: false, }).paths; for (index = 0; index < entries.length; ++index) { value = entries[index]; if (entries[index].split('.')[1] === extension) { filePath = value; break; } } if (filePath != undefined){break} //We found it, don't search up a level } if (filePath == undefined) { //The file doesn't exist. Ask the user filePath = sf.interaction.selectFile({ defaultLocation: sessionDir.split('/').slice(0, -1).join('/'), prompt: 'Please select a file to open', }).path; } sf.file.open({ path: filePath });
Chris Shaw @Chris_Shaw2020-05-22 22:41:59.467Z
Thanks for this Andrew!
For some reason I can't get my Mac to show the file extension for Synchronize!X files. However I consistently label al my backup files with this format "project/artist name - BU" so searching for "- BU" should work for me.
I very rarely have more than one backup file document per project.I'll give this a go and let you know how it works.
Thanks again!Andrew Scheps @Andrew_Scheps
No worries. If you get info in the finder on a file it should show up there and the script can see it even if they're hidden in the finder.
Chris Shaw @Chris_Shaw2020-05-22 23:29:24.695Z
That's the thing - Get Info doesn't show a file type.
I'll email you a copy of the file - it's tiny. Perhaps you can make sense of it.
- In reply toChris_Shaw⬆:
Chris Shaw @Chris_Shaw2020-05-22 23:06:59.039Z
Unfortunately this doesn't seem to be working. I can't get my mac to display the file extension for the Synchronize! X document which is really weird (not even in the terminal) so I can't tell if you're using the right extension. IF you know of a way to display the file type besides changing the Finder Prefs let me know.
In the meantime, is it possible to change the script to open any file that ends with "- BU"?
Chris Shaw @Chris_Shaw2020-05-22 23:13:49.741Z
To be clear I think the script is working properly but it isn't finding the backup file. Even if I place it directly in the session folder.
Andrew Scheps @Andrew_Scheps
Wow, that's so weird! I have the Pro version and the files have the file extension, these don't. It's a little different to do a part of the filename so give me a sec...
- In reply toChris_Shaw⬆:
Andrew Scheps @Andrew_Scheps
Ok, here's a new one. This looks for a '-' in the filename and then sees if the only text after it is ' BU'. It's not as foolproof as using an extension but should work.
//The file extension for saved sync files const string = ' BU' // This sets the search directory to the curren session folder var sessionDir = sf.ui.proTools.mainWindow.sessionPath; var searchDir = '' var directoryDepth = sessionDir.split('/').length - 1 //how deep in the file structure are we, then adjust to keep from going up oast the root of the drive var level, index, value, filePath; for (level = 1; level < directoryDepth; level++) { searchDir = sessionDir.split('/').slice(0, -level).join('/') let entries = sf.file.directoryGetEntries({ path: searchDir, includeDirectories: false, }).paths; for (index = 0; index < entries.length; ++index) { value = entries[index]; if (entries[index].split('-')[1] === string) { filePath = value; break; } } if (filePath != undefined){break} //We found it, don't search up a level } if (filePath == undefined) { //The file doesn't exist. Ask the user filePath = sf.interaction.selectFile({ defaultLocation: sessionDir.split('/').slice(0, -1).join('/'), prompt: 'Please select a file to open', }).path; } sf.file.open({ path: filePath });
Andrew Scheps @Andrew_Scheps
Here's one that's slightly safer. The previous one wouldn't find your backup file if there was a hyphen anywhere else in the file name. This one checks the end of the filename for ' - BU' which should be unique I hope.
//The ending string in the filename for saved sync files const string = ' - BU' // This sets the search directory to the current session folder var sessionDir = sf.ui.proTools.mainWindow.sessionPath; var searchDir = '' var directoryDepth = sessionDir.split('/').length - 1 //how deep in the file structure are we, then adjust to keep from going up past the root of the drive var level, index, value, filePath; for (level = 1; level < directoryDepth; level++) { searchDir = sessionDir.split('/').slice(0, -level).join('/') let entries = sf.file.directoryGetEntries({ path: searchDir, includeDirectories: false, }).paths; for (index = 0; index < entries.length; ++index) { value = entries[index]; if (entries[index].slice(-5) === string) { filePath = value; break; } } if (filePath != undefined){break} //We found it, don't search up a level } if (filePath == undefined) { //The file doesn't exist. Ask the user filePath = sf.interaction.selectFile({ defaultLocation: sessionDir.split('/').slice(0, -1).join('/'), prompt: 'Please select a file to open', }).path; } sf.file.open({ path: filePath });
- In reply toKhonnor_Wallace⬆:Chris Shaw @Chris_Shaw2020-05-22 23:58:38.471Z
Hell. Yeah!
That works! I think my "-BU" naming convention should be pretty bullet proof for me because I use it very consistently.Thanks so much!
- In reply toKhonnor_Wallace⬆:Chris Shaw @Chris_Shaw2020-05-23 00:05:02.714Z
This is going to be a heavily used / useful script.
BTW - I broke down and got a Stream Deck (5x3). I was programming pages in the Avid control app but coming up with unique keystrokes became tiresome and moving softkeys around in it is excruciating. Plus the portability of bringing a StreamDeck to another studio and not having to copy over pref files for Eucon etc makes life so much easier.Andrew Scheps @Andrew_Scheps
Yeah, the Stream Deck really changes things. I can't remember keystrokes no matter how logical I think I'm being so I've got tons of stuff on buttons and decks and I'm trying to be smarter about having the decks load dynamically. I'm working on some very cool scripts to use the SD more interactively too (bypassing plugins using SD buttons anyone?)
Chris Shaw @Chris_Shaw2020-05-23 01:40:20.291Z
Christian mentioned somewhere that they're working on making the buttons more dynamic in the way they display information. That will be a game changer. Plugin buttons for bypass that display the plugin names depending on track selection would be cool. Or how about having system usage percentage on a button.
So many possibilities.
I'm more excited about SF updates than PT updates…Andrew Scheps @Andrew_Scheps
I have the first one working already, just trying to fix one last bug.
- In reply toKhonnor_Wallace⬆:Daniel Perez @daniel_perez
I'd like to just open the Audio Files Folder from the current session I'm using. Could you paste the right code for me?
- LLukas paschke @Lukas_paschke
same here
Raphael Sepulveda @raphaelsepulveda2024-08-08 16:48:42.513Z
Here you go!
function openCurrentSessionAudioFilesFolder() { if (!sf.app.proTools.hasOpenSession) throw "No session is currently open."; const sessionPath = sf.ui.proTools.mainWindow.sessionPath; const parentPath = sessionPath.split("/").slice(0, -1).join("/"); const audioFilesPath = `${parentPath}/Audio Files`; sf.file.open({ path: audioFilesPath }); } openCurrentSessionAudioFilesFolder();