Copy Selected Files from Finder Copying Random/Unselected Files
Title
Copy Selected Files from Finder Copying Random/Unselected Files
What do you expect to happen when you run the script/macro?
This should simply copy the selected files to the current Pro Tools Session's Bounced Files Folder.
Are you seeing an error?
What happens when you run this script?
It is copying a lot of other random file's that are not selected.
How were you running this script?
I used a Stream Deck button
How important is this issue to you?
5
Details
{ "inputExpected": "This should simply copy the selected files to the current Pro Tools Session's Bounced Files Folder.", "inputIsError": false, "inputWhatHappens": "It is copying a lot of other random file's that are not selected.", "inputHowRun": { "key": "-MpfwmPg-2Sb-HxHQAff", "title": "I used a Stream Deck button" }, "inputImportance": 5, "inputTitle": "Copy Selected Files from Finder Copying Random/Unselected Files" }
Source
function getProToolsSessionFolder() {
sf.ui.proTools.appActivate();
sf.ui.proTools.mainWindow.invalidate();
let sessionFolder = sf.ui.proTools.mainWindow.sessionPath.split('/').slice(0, -1).join('/');
return sessionFolder;
}
function main() {
let selectedFinderPaths = sf.ui.finder.selectedPaths
let sessionFolder = getProToolsSessionFolder();
sf.ui.finder.appActivate();
selectedFinderPaths.forEach(path => {
let splitPathArray = path.split('/');
let selectedFileName = splitPathArray.slice(-1)[0];
sf.file.copy({
sourcePath: `${path}`,
destinationPath: `${sessionFolder}/Bounced Files/${selectedFileName}`,
});
});
sf.ui.proTools.appActivate();
}
main();
Links
User UID: EoVu20w2ZRTvmJvgozc57ZXuAhU2
Feedback Key: sffeedback:EoVu20w2ZRTvmJvgozc57ZXuAhU2:-NhDWPY4GZROs5YvN0zd
Feedback ZIP: HHOHTw3XrrYg7DisY2FejB2DqRD3j+JsHWrPISDQABee3GhscyUWIBKkLICyaVxwL/DbASY4VsFyBZ2V+80FjGDa8i3n29a8mzFwSZ5961dA6lq/KTpjwwc5YDgGO5n6IMhFjpwlrwt6DA/q28mzZlFOOvDDbDBHNQnGArSjJHiA4S4gWQjYLT9uUAzkedY1ibjXNS5+15xzlAbVWN47uq5wMFon/kDUH41sTsPbJiYv8jhP5DSgFDUWHwydvpUX7SNnF3Ft38mM88mXp18msC4PIKOZrYzAEg8mTW4rVBGmQre75EgZD50e5gJFjNB/Ds7Ak1jJgyGarkbRbln2ruRWoSXKt+zaOT9U0nSzXYo=
- Nathan Salefski @nathansalefski
Here's an example
Chad Wahlbrink @Chad2023-10-21 13:51:18.727Z
Can you give an example (screenshots ideally) of what kind files you are copying and what you expect the result to be?
Are you copying a "folder"?Nathan Salefski @nathansalefski
Sure this was a test to solve someone’s problem in the forum. I was just copying a simple screen recording from the desktop over to the currently open Pro Tools Session’s Bounced Files folder. At one point this code copied my entire Applications folder that above screenshot shows the screen recording from my desktop I tried to copy along with all the other random files
- In reply tonathansalefski⬆:Chad Wahlbrink @Chad2023-10-21 13:56:32.502Z2023-10-21 14:35:19.253Z
I did a bit of a deep dive on file manipulation here, and I'm curious if it would help.
let splitPathArray = path.split('/'); let selectedFileName = splitPathArray.slice(-1)[0];
My theory is that if you are using the above code, and trying to copy a folder of files, you may actually copy all of the contents within that folder, including hidden files, etc. This may be because by using
.split('/')
, the script throws away the/
at the end of the folder's file path.
In order to copy a folder you'd have to use something like:let currentSessionBouncedFilesFolder = sf.app.proTools.getSessionPath().sessionPath.split(':').slice(0,-1).join('/').slice(1) +'/Bounced Files/'; sf.ui.finder.selectedPaths.forEach(currentFinderFile => { let fileName; // if the selected file is a folder, keep the '/' as part of the fileName if(currentFinderFile.split('/').slice(-1)[0] === ''){ fileName = currentFinderFile.split('/').slice(0,-1).slice(-1)[0] + '/'; sf.file.copy({sourcePath:currentFinderFile, destinationPath: currentSessionBouncedFilesFolder + fileName }); // if the selected file is a file } else { fileName = currentFinderFile.split('/').slice(-1)[0] sf.file.copy({sourcePath:currentFinderFile, destinationPath: currentSessionBouncedFilesFolder + fileName }); } })
Nathan Salefski @nathansalefski
Yea that was actually the exact post I was trying to fix and ended up breaking my own lol. I know @chrscheuer showed me a way to copy folders using the command line. I took part of that and tried to reapply it here. I’ll give that test a go shortly