No internet connection
  1. Home
  2. How to

Finder scripting advise - (Name contains x, then move to folder)

By Ryan @Ryno
    2023-09-02 09:05:11.236Z

    Hi Wizards,

    I’m just thinking of ways to speed up my session prep even more.
    Is it possible to write a script that works in the macOS Finder and does the following?:

    Looks for file names containing x and moves them to a specified folder?

    The script could do something like:

    Select files with names containing “Kick, Snare, Hat, OH, Ride, Tom etc)” and move to a folder called drums. That way you could drag the contents of this folder into the Pro Tools edit window and then run a SoundFlow script to run a chain of events like:

    Add selected tracks to new routing folder, colour them the drums colour, group and assign to a vca and then recall a track preset on the routing folder.

    Before running this script, I’d run all files through Blake Eisman’s handy StereoMonoizer app :)

    • 1 replies
    1. D
      danielkassulke @danielkassulke
        2023-09-03 23:34:37.909Z

        Hey Ryan,

        Here's a snippet to help you do the first bit. Note you'll have to substitute filepath values on line 1 and 10:

        const desktopDir = "/Users/YourUserProfile/Desktop";
        
        // Get all files and folders on the desktop
        const allFilesAndFolders = sf.file.directoryGetFiles({ path: desktopDir }).paths;
        
        // Check for the presence of a folder called "Drums" on the desktop
        const drumFolderExists = allFilesAndFolders.some(path => path.endsWith('/Drums'));
        
        // Create "Drums" folder if it doesn't exist
        const destinationFolder = '/Users/YourUserProfile/Desktop/Drums';
        if (!drumFolderExists) {
            sf.file.directoryCreate({ path: destinationFolder });
        }
        
        // Get all .wav files on the desktop
        const allWavFiles = sf.file.directoryGetFiles({ path: desktopDir, searchPattern: '*.wav', isRecursive: true }).paths;
        
        // Add specific drum file names
        const drumFiles = ['Kick', 'Snare', 'Hat', 'OH', 'Ride', 'Tom'];
        
        // Filter for drum files
        const drumNameFiles = allWavFiles.filter(file => {
            const fileName = file.split('/').pop();
            const fileNameWithoutExtension = fileName.split('.').slice(0, -1).join('.');
            return drumFiles.includes(fileNameWithoutExtension);
        });
        
        if (drumNameFiles.length > 0) {
            for (let path of drumNameFiles) {
                // Build the destination path
                const destinationPath = `${destinationFolder}/${path.split('/').pop()}`;
                
                // Move the file to "Drums" folder
                sf.file.move({
                    sourcePath: path,
                    destinationPath: destinationPath,
                });
            }
            alert('Files have been moved');
        } else {
            alert('No drum files were found on your Desktop.');
        }