No internet connection
  1. Home
  2. How to

Looking to make script to save a folder of Kontakt patches as PT Track Presets

By Judson Crane @Judson_Crane
    2024-01-04 04:34:08.786Z2024-01-04 07:01:12.526Z

    Hello-
    I'm looking to emulate a keyboard maestro macro I made a few years ago in order to understand SoundFlow better and wondering if someone can help. I've gotten through the prompts and variables thus far but not sure what to do next... in KBM I would:

    1. mouse target/click the instrument name area in the kontakt patch
    2. use command A to select all, and the command c to copy
    3. enter the rename track dialog box and paste this data into the track name, tab over to comments and paste the Library variable there.
    4. hit enter, and execute save track preset shortcut, and paste a combo of the two variables here. hit enter
    5. target the kontakt instance again and click the right arrow that is to the right of the instrument name to move to the next patch.
    6. this would repeat the number of times of my totalInstruments variable.
      here is my script so far:
    sf.ui.proTools.appActivateMainWindow();
    sf.ui.proTools.mainWindow.invalidate();
    
    var totalInstruments;
    var libraryName;
    var pauseTime;
    
    var totalInstruments = prompt("Enter number of Kontakt patches you wish to save.");
    log(totalInstruments);
    
    var libraryName = prompt("Enter the name of the sample library (will appear in the Comments).");
    log(libraryName);
    
    var pauseTime = prompt("Enter the amount of time to pause between saving presets.");
    log(pauseTime);
    
    sf.ui.proTools.windows.whoseTitle.is("Plug-in: Kontakt 7").first.mouseClickElement({
        relativePosition: {"x":716,"y":192},
        anchor: "TopLeft",
        isRightClick: false,
    });
    
    sf.keyboard.press({
        keys: "cmd+a",
    });
    
    sf.keyboard.press({
        keys: "cmd+c",
    });
    
    sf.ui.proTools.appActivateMainWindow();
    
    sf.wait(500);
    
    sf.keyboard.press({
        keys: "cmd+shift+return",
    });
    
    sf.wait(500);
    
    sf.ui.proTools.menuClick({
        menuPath: ["Edit","Paste"],
    });
    
    
    sf.keyboard.press({
        keys: "tab",
    });
    
    sf.keyboard.type({
        text: libraryName,
    });
    
    sf.keyboard.press({
        keys: "return",
    });
    
    sf.ui.proTools.menuClick({
        menuPath: ["Track","Save Track Preset..."],
    });
    
    sf.keyboard.press({
        keys: "tab",
    });
    
    sf.keyboard.type({
        text: libraryName,
    });
    sf.wait(1000);
    
    sf.keyboard.press({
        keys: "return",
    });
    sf.wait(1000);
    sf.keyboard.press({
        keys: "return",
    });
    sf.wait(500);
    sf.ui.proTools.windows.whoseTitle.is("Plug-in: Kontakt 7").first.mouseClickElement({
        relativePosition: {"x":882,"y":195},
        anchor: "TopLeft",
        isRightClick: false,
    });
    
    // command here to either wait for the kontakt loading window to close or to wait for pauseTime seconds
    // command here to repeat totalInstruments number of times!
    

    in KBM I would use screen captures, bits of the graphics to orient the mouse clicking. I found the YouTube vid on relative to UI element clicking / using coordinates from screen shot command... cool that is working!

    FWIW, Keyboardmaestro allows recording of coordinates directly into the app... this screenshot trick from the YouTube vid was helpful but difficult as the coordinates are sooooo tiny on my 4k monitor, I had to almost guess at what some of the numbers were. would be nice to integrate that part into the functionality of the scripting somehow.

    So I guess I only need assistance on how to do the loop repeat (totalInstruments number of times) from line 17 to line 83?

    Any assistance is really appreciated. hopefully this can be a useful script for others, i have found it really helpful when acquiring new kontakt libraries that have tons of instruments.
    much thanks

    • 5 replies
    1. marcello azevedo @marcello_azevedo
        2024-01-04 08:11:30.746Z

        That’s as interesting one.
        I don’t have an answer for you but will tag along to see if something comes up.

        1. In reply toJudson_Crane:

          I have a free app in the store called "Get X/Y Coordinates, Window, and Mouse Info" that will grab the X/Y coordinates of the current mouse position relative to the active window and other useful info. The results can be copied directly from the dialog box or saved to the log.

          1. JJudson Crane @Judson_Crane
              2024-01-04 19:13:02.643Z

              ah fantastic, that will be so helpful, thank u!
              Do you know a good resource to learn how to loop / repeat functions?
              And in KBM, I would just pause between loops to let the kontakt inst load (which was pretty quick usually), but ideally the script is simply waiting for the kontakt loading window to close before continuing. Is there a good way to accomplish this? Thanks for the help.

            • J
              In reply toJudson_Crane:
              Judson Crane @Judson_Crane
                2024-01-04 23:38:18.185Z

                did some digging on loops... I think I'd use this code?

                for(let i=0; i<var totalInstruments; i++) {
                // the process
                }
                

                did I do the variable right?

                the kontakt loading window closing is a different story... here is what it looks like:

                How do I have the script wait to move on to the next command until this window closes?
                thx!!

                1. J
                  In reply toJudson_Crane:
                  Judson Crane @Judson_Crane
                    2024-01-08 17:27:15.362Z

                    this is a functional version of this script now. You would need to do a few things for it to work on your own system:

                    set PT keyboard shortcut for rename track to command-shift-return
                    check and adjust the mouse click coordinates for your kontakt 7 window for selecting the instrument name in the kontakt window
                    check and adjust the mouse click coordinates for your kontakt 7 window for the right arrow to move to next patch.
                    make sure your track color and output bus for the track are set how you want them before starting! load the first instrument in the folder and start the script.
                    It will save the presets to your first Track Presets folder I believe. I have a folder called 00 Temp where it saves these to. After the script runs I manually move them to desired location. I just saved a folder of 70 Track Presets successfully!

                    I'm not using the pauseTime variable and just have this hard coded to 1.5 seconds before each loop restarts. I'm not sure if this script will work with high memory instruments yet, as that kontakt loading window would last a lot longer for those.

                    How would I replace that hard coded wait at the end to a wait that lasted for "pauseTime" seconds?

                    How do I display a message at the end of the script that says "totalInstruments Track Presets saved!"

                    thx!

                    sf.ui.proTools.appActivateMainWindow();
                    sf.ui.proTools.mainWindow.invalidate();
                    
                    var totalInstruments;
                    var libraryName;
                    var pauseTime;
                    
                    var totalInstruments = prompt("Enter number of Kontakt patches you wish to save.");
                    log(totalInstruments);
                    
                    var libraryName = prompt("Enter the name of the sample library (will appear in the Comments).");
                    log(libraryName);
                    
                    //var pauseTime = prompt("Enter the amount of time to pause between saving presets.");
                    //log(pauseTime);
                    
                    for(let i=0; i<totalInstruments; i++) {
                    
                        //Here you put the stuff you want repeated totalInstruments times
                    
                    
                    sf.ui.proTools.windows.whoseTitle.is("Plug-in: Kontakt 7").first.mouseClickElement({
                        relativePosition: {"x":716,"y":192},
                        anchor: "TopLeft",
                        isRightClick: false,
                    });
                    
                    sf.keyboard.press({
                        keys: "cmd+a",
                    });
                    
                    sf.wait(500);
                    
                    sf.keyboard.press({
                        keys: "cmd+c",
                    });
                    
                    sf.wait(500);
                    
                    sf.ui.proTools.appActivateMainWindow();
                    
                    sf.wait(500);
                    
                    sf.keyboard.press({
                        keys: "cmd+shift+return",
                    });
                    
                    sf.wait(500);
                    
                    sf.ui.proTools.menuClick({
                        menuPath: ["Edit","Paste"],
                    });
                    
                    sf.wait(500);
                    
                    sf.keyboard.press({
                        keys: "tab",
                    });
                    
                    sf.keyboard.type({
                        text: libraryName,
                    });
                    
                    sf.keyboard.press({
                        keys: "return",
                    });
                    
                    sf.ui.proTools.menuClick({
                        menuPath: ["Track","Save Track Preset..."],
                    });
                    
                    sf.keyboard.press({
                        keys: "tab",
                    });
                    
                    sf.keyboard.type({
                        text: libraryName,
                    });
                    sf.wait(1000);
                    
                    sf.keyboard.press({
                        keys: "return",
                    });
                    sf.wait(1000);
                    sf.keyboard.press({
                        keys: "return",
                    });
                    sf.wait(500);
                    sf.ui.proTools.windows.whoseTitle.is("Plug-in: Kontakt 7").first.mouseClickElement({
                        relativePosition: {"x":882,"y":195},
                        anchor: "TopLeft",
                        isRightClick: false,
                    });
                    
                    sf.ui.proTools.confirmationDialog.elementWaitFor({ waitType: 'Disappear', timeout: -1 }); //-1 is endless timeout (cancel by Ctrl+Shift+Esc)
                    
                    sf.wait(1500);
                    }
                    
                    log("Track Presets Saved");
                    

                    emphasized text**emphasized text