Hi I'm fairly new at this so forgive me if the answer is quite simple... but I'm looking to create some commands that will open up sessions based on part of their filename. I have 6 Pro Tools sessions in one folder, each session always has either a "R1", "R2", "R3", "R4", "R5", or "R6" in the filename, but the full filename is constantly changing depending on the date, who is working in the session etc. Hoping to create a script that navigates to a specific folder, and IF the file extension is ".ptx" and the filename contains "R1" then the script duplicates that session, moves the duplicate to an "old" folder, renames the "R1" session with today's date and opens up that session.
- JIn reply tojoseph_winterbotham⬆:joseph winterbotham @joseph_winterbotham
I guess these are the steps I'm looking for. Surfing through the forum, I think I've learned how to write steps 1, 4, 6 and 9. I could probably achieve some of these steps with key presses but if there is another way, I think I'd like to do it.
-
Navigate to directory/folder: "SESSIONS"
-
Select file that filename contains “.ptx” and “R1”
-
Duplicate file
-
Move duplicate to “old” folder
-
Rename duplicate: deleting “ copy” from the filename
-
Navigate to directory/folder "SESSIONS"
-
Select file that contains “.ptx” and “R1”
-
Rename file: replace old date with today’s date eg. "220401" to "220402"
-
Open file
Christian Scheuer @chrscheuer2022-04-01 16:03:31.631Z
Hi Joseph.
All of this could be done just by operating directly on the files (no need to automate Finder).
But there's a logic step that feels wrong. Step 4, moving the file to "old" folder would overwrite what's in that folder with the same name.. How should that be handled? Or are you sure there's nothing in the old folder with that particular name?
Can you give some examples (before/after screenshots)? That would make it easier to reason about.Christian Scheuer @chrscheuer2022-04-01 16:08:01.479Z
You should be able to get started with something like this, but to replace the date we would need to know where to locate the date in the filename:
This looks in the "SESSIONS" folder on the desktop.
const directoryPath = "~/Desktop/SESSIONS"; const oldDirectoryName = "old"; const reelNumber = 'R1'; let allSessionPaths = sf.file.directoryGetFiles({ path: directoryPath, searchPattern: '*.ptx' }).paths; let firstMatchingReelSessionPath = allSessionPaths.filter(p => p.includes(reelNumber))[0]; if (!firstMatchingReelSessionPath) throw `No session found for reel ${reelNumber}`; //Copy it to 'old' sf.file.copy({ sourcePath: firstMatchingReelSessionPath, destinationPath: directoryPath + '/' + oldDirectoryName + '/' + firstMatchingReelSessionPath.split('/').slice(-1)[0], }); //TODO: Rename the date
Christian Scheuer @chrscheuer2022-04-01 16:13:16.862Z
Actually, this might just do the trick:
const directoryPath = "~/Desktop/SESSIONS"; const oldDirectoryName = "old"; const reelNumber = 'R1'; let allSessionPaths = sf.file.directoryGetFiles({ path: directoryPath, searchPattern: '*.ptx' }).paths; let firstMatchingReelSessionPath = allSessionPaths.filter(p => p.includes(reelNumber))[0]; if (!firstMatchingReelSessionPath) throw `No session found for reel ${reelNumber}`; let oldFilename = firstMatchingReelSessionPath.split('/').slice(-1)[0]; //Copy it to 'old' sf.file.copy({ sourcePath: firstMatchingReelSessionPath, destinationPath: directoryPath + '/' + oldDirectoryName + '/' + oldFilename, }); //Rename the date let match = oldFilename.match(/^(.*)(\d\d\d\d\d\d)(.*)\.ptx/i); let d = new Date(); let today = d.getFullYear().toString().slice(-2) + (d.getMonth() + 1).toString().padStart(2, '0') + d.getDate().toString().padStart(2, '0'); let newFilename = `${match[1]}${today}${match[3]}.ptx`; sf.file.move({ sourcePath: firstMatchingReelSessionPath, destinationPath: directoryPath + '/' + newFilename, });
- Jjoseph winterbotham @joseph_winterbotham
I'm amazed, this is fantastic. It's copying to the "old" folder and changing the date of the original session perfectly. The last thing... I thought I knew how to write the last step, to open the newly renamed session... but I was wrong.
//Open Session sf.file.open({ path:directoryPath + firstMatchingReelSessionPath });
What am I doing wrong here?
Christian Scheuer @chrscheuer2022-04-01 17:19:20.357Z
Yay :) This should do it:
sf.file.open({ path: directoryPath + '/' + newFilename, });
- Jjoseph winterbotham @joseph_winterbotham
This works great!! I'm in a whole new world. I swear I'll stop bothering you after this but how would you add a rename function to this script that replaces one set of initials with another set of initials, like replace "JW" with "EG"?
-
- JIn reply tojoseph_winterbotham⬆:joseph winterbotham @joseph_winterbotham
Thank you so much Christian! This is great. And you're right, I would like to overwrite the file in the "old" folder if the same filename exists. So far, this is doing great finding the correct session and copying to the old folder. As for the date, it's always the last 6 characters in the filename example below:
"Project Title_R1v(Version number)_JW FX_Date.ptx" = "TLM_R1v6_JW FX_220331.ptx"