No internet connection
  1. Home
  2. Support

Soundflow not going to designated track in script, causing script to fail.

By Randall Smith @Randall_Smith
    2022-10-07 21:33:55.636Z

    Soundflow not going to designated track in script, causing script to fail.

    System Information

    SoundFlow 5.1.11

    OS: darwin 17.7.0

    ProductName: Mac OS X
    ProductVersion: 10.13.6
    BuildVersion: 17G8037

    Steps to Reproduce

    1. Select length of Guide Track.
    2. Run Level GT script

    Expected Result

    Should select Guide Track in session (hard coded into script). Measure loudness. Prompt for loudness reading. Drop level to hit -24.1 and coalesce volume to clip gain.

    Actual Result

    doesn't select Guide Track. Selects random track instead.

    Workaround

    Revert to v5.0.5

    Other Notes

    I have video of this if needed. There doesn't seem to be a work around for this one yet outside of reverting versions.


    Links

    User UID: h5usDXSaKHSy12ByPzI67bSN9353

    Feedback Key: sffeedback:h5usDXSaKHSy12ByPzI67bSN9353:-NDoMc-ErbWGXpu0w3Lj

    Feedback ZIP

    • 14 replies

    There are 14 replies. Estimated reading time: 39 minutes

    1. R
      Randall Smith @Randall_Smith
        2022-10-07 21:40:28.045Z
        
        //sf.ui.proTools.viewCloseFloatingWindows();
        
        sf.ui.proTools.menuClick({
            menuPath: ["Window", "Configurations", "1: Blank"],
        });
        
        
        sf.ui.proTools.menuClick({
            menuPath: ["View", "Other Displays", "Clip List"],
            targetValue: "Enable",
        });
        
        //if (targetLoudness >= measuredLoudness) {
        //    alert("Need to lower Track");
        //} else if (targetLoudness <= measuredLoudness) {
        //    alert("Need to Raise Track");
        //} else {
        //    alert("No Action Needed");
        //}
        
        
        
        function getLoudness() {
        
            sf.ui.proTools.appActivateMainWindow();
        
            const popupMenu = sf.ui.proTools.clipOpenContextMenu().popupMenu;
        
            popupMenu.menuClickPopupMenu({
                menuPath: ["Import Audio From Movie"],
            });
        
            sf.ui.proTools.windows.whoseTitle.is('Open').first.elementWaitFor();
        
            sf.ui.proTools.windows.whoseTitle.is('Open').first.getElement('AXDefaultButton').elementClick();
        
            sf.ui.proTools.windows.whoseTitle.is('Track Import Window').first.elementWaitFor({
                waitType: "Appear",
            });
        
            sf.ui.proTools.windows.whoseTitle.is('Track Import Window').first.buttons.whoseTitle.is('OK').first.elementClick();
        
            //sf.ui.proTools.waitForNoModals(); 
        
            sf.wait({
                intervalMs: 1000,
            });
        
            sf.ui.proTools.windows.whoseTitle.is('Audio Import Options').first.radioButtons.allItems[1].checkboxSet({
                targetValue: "Enable",
            });
            sf.ui.proTools.windows.whoseTitle.is('Audio Import Options').first.popupButtons.first.popupMenuSelect({
                menuPath: ["Selection"],
            });
        
        
            sf.keyboard.press({
                keys: "numpad enter",
            });
            sf.wait({
                intervalMs: 1000,
            });
        
            //const names = sf.ui.proTools.trackGetSelectedTracks().names;
        
            //alert (names);
            // sf.keyboard.press({
            //     keys: "shift+tab",
            // });
        
            sf.ui.proTools.menuClick({
                menuPath: ["Edit", "Cut"],
            });
        
        
            sf.ui.proTools.trackGetByName({ name: "Guide Track", makeVisible: true }).track.trackSelect();
            sf.wait({
                intervalMs: 250,
            });
            sf.ui.proTools.menuClick({
                menuPath: ["Edit", "Paste"],
            });
        
            /* sf.keyboard.press({
                keys: "cmd+v",
            }); */
        
            sf.ui.proTools.audioSuiteOpenPlugin({
                category: "Sound Field",
                name: "NUGEN VisLM2",
            });
        
            sf.ui.proTools.firstAudioSuiteWindow.buttons.whoseTitle.is('Analyze').first.elementClick();
        
            sf.ui.proTools.waitForNoModals();
        
        }
        
        function findDifference(number1, number2) {
            const measuredDifference = (number2 - number1);
            const measuredDifference = measuredDifference.toFixed(1);
            //alert(measuredDifference);
            //alert(Math.sign(measuredDifference));
            //  Number.isFinite(measuredDifference);
            //return measuredDifference;
        
            sf.ui.proTools.appActivateMainWindow();
        
            sf.ui.proTools.trackSelectByName({
                names: ["Guide Track"],
            });
        
            sf.ui.proTools.trackGetByName({ name: "Guide Track", makeVisible: true }).track.trackOutputToggleShow();
        
            sf.ui.proTools.mainTrackOutputWindow.textFields.whoseTitle.is('Volume Numerical').first.elementClick();
            sf.keyboard.press({ keys: "cmd+c", });
        
            // sf.clipboard returns a text string 
            // the '+' in the statement below converts the string to number
        
            // const nowVolume = +sf.clipboard.getText().text;
            sf.keyboard.type({ text: (measuredDifference).toString() });
            sf.keyboard.press({ keys: 'enter' });
        
            sf.ui.proTools.automationWriteAutoToSelectionAndClear();
        
            sf.ui.proTools.trackGetByName({ name: "Guide Track", makeVisible: true }).track.automationModeSet({
                automationModeName: "Trim",
            });
        
            sf.ui.proTools.menuClick({
                menuPath: ["Edit", "Automation", "Coalesce Volume Automation to Clip Gain"],
            });
        
        };
        
        function findDifferenceMasterVca(number1, number2) {
            const measuredDifference = (number2 - number1);
            const measuredDifference = measuredDifference.toFixed(1);
            //alert(measuredDifference);
            //alert(Math.sign(measuredDifference));
            //  Number.isFinite(measuredDifference);
            //return measuredDifference;
        
            sf.ui.proTools.appActivateMainWindow();
            sf.ui.proTools.automationPreview();
        
            sf.ui.proTools.trackGetByName({ name: "* Master", makeVisible: true }).track.automationModeSet({
                automationModeName: "touch",
            });
        
            sf.ui.proTools.trackGetByName({ name: "* Master", makeVisible: true }).track.automationModeSet({
                automationModeName: "Trim",
            });
            sf.ui.proTools.trackSelectByName({
                names: ["* Master"],
            });
        
            sf.ui.proTools.trackGetByName({ name: "* Master", makeVisible: true }).track.trackOutputToggleShow();
        
            sf.ui.proTools.mainTrackOutputWindow.textFields.whoseTitle.is('Volume Numerical').first.elementClick();
            sf.keyboard.press({ keys: "cmd+c", });
        
            // sf.clipboard returns a text string 
            // the '+' in the statement below converts the string to number
        
            // const nowVolume = +sf.clipboard.getText().text;
            sf.keyboard.type({ text: (measuredDifference).toString() });
            sf.keyboard.press({ keys: 'enter' });
        
            sf.ui.proTools.automationWriteAutoToSelectionAndClear();
        
            sf.ui.proTools.trackGetByName({ name: "* Master", makeVisible: true }).track.automationModeSet({
                automationModeName: "Trim",
            });
        
            //.200.sf.ui.proTools.menuClick({
            //    menuPath: ["Edit", "Automation", "Coalesce Volume Automation to Clip Gain"],
            // });
        
        };
        
        //sf.keyboard.type({ text: (nowVolume - measuredDifference).toString() });
        
        //getLoudness();
        sf.ui.proTools.audioSuiteOpenPlugin({
            category: "Sound Field",
            name: "NUGEN VisLM2",
        });
        
        sf.ui.proTools.firstAudioSuiteWindow.buttons.whoseTitle.is('Analyze').first.elementClick();
        
        sf.ui.proTools.waitForNoModals();
        
        var measuredLoudness = prompt("What was the measured Loudness");
        
        sf.ui.proTools.trackGetByName({ name: "Guide Track", makeVisible: true }).track.automationModeSet({
            automationModeName: "touch",
        });
        
        sf.ui.proTools.trackGetByName({ name: "Guide Track", makeVisible: true }).track.automationModeSet({
            automationModeName: "Trim",
        });
        
        sf.ui.proTools.menuClick({
            menuPath: ["Window", "Automation"],
        });
        
        sf.ui.proTools.automationPreview();
        
        findDifference(targetLoudness, measuredLoudness)
        //findDifferenceMasterVca(targetLoudness, measuredLoudness)
        
        
        sf.ui.proTools.menuClick({
            menuPath: ["Window", "Configurations", "1: Blank"],
        });
        
        1. Thanks for posting this Randall!

          I'll have Kitch take a look to dive into this.

          1. @Kitch we should double check this with PT 2020.12 and check if there are any regressions with code like this:

             sf.ui.proTools.trackGetByName({ name: "Guide Track", makeVisible: true }).track.trackSelect();
            

            Kitch: This should probably also have a few invalidate calls added, especially after window config changes.

            Please also note the "getLoudness" function uses clipOpenContextMenu, which is definitely one of the less stable functions in general as it relies on centering the audio clip on screen and simulating a right click.

            It would be very helpful to know exactly when in this script things go wrong. From your description, Randall, does it start by selecting the Guide Track and then it goes wrong later, or does it start by selecting the wrong track altogether from the start?

            1. Kitch Membery @Kitch2022-10-09 10:31:46.043Z

              Sounds good @chrscheuer,

              I'll take a look at it tomorrow and Monday. :-)

              1. In reply tochrscheuer:
                RRandall Smith @Randall_Smith
                  2022-10-10 16:51:48.586Z

                  Thank you for looking into this. The script fails because it selects a track other than "Guide Track". The script runs properly after that, it just picks a random track instead of the one that is defined as a constant.

              2. In reply toRandall_Smith:
                Kitch Membery @Kitch2022-10-10 01:30:32.361Z

                Hi @Randall_Smith,

                Based on the "Expected Result" description you wrote, the following script should accomplish what you are after.

                I've added comments to the code so that you can understand what is happening in each line of code. Let me know if it works for you, or if there is anything that I've missed.

                const guideTrackName = "Guide Track";
                const targetLoudnessValue = -24.1;
                const windowConfigurationName = "1: Blank";
                
                
                function measureClipLoudness() {
                    //Open the Vis LM2 AudioSuite window
                    const visLm2Window = sf.ui.proTools.audioSuiteOpenPlugin({
                        category: "Sound Field",
                        name: "NUGEN VisLM2",
                    }).window;
                
                    //Wait for Vis LM2 AudioSuite window
                    visLm2Window.elementWaitFor();
                
                    //Analyse the selection
                    visLm2Window.buttons.whoseTitle.is('Analyze').first.elementClick();
                
                    //Wait for Analysis to finish
                    sf.ui.proTools.waitForNoModals();
                }
                
                /** @param {{numberField:AxElement, targetValue: string}} args */
                function setNumberFieldValue({ numberField, targetValue }) {
                    if (numberField.value.invalidate().value.trim() !== targetValue) {
                
                        const oldClipboardText = sf.clipboard.getText().text;
                
                        try {
                            const text = targetValue;
                            sf.clipboard.setText({ text: text });
                
                            numberField.elementClick();
                
                            sf.keyboard.press({ keys: "cmd+v", });
                
                            var i = 0;
                
                            do {
                                sf.wait({ intervalMs: 1 });
                                i++
                
                                if (i >= 5) { throw `Could not update the number field` }
                            } while (numberField.value.invalidate().value !== targetValue);
                
                            sf.keyboard.press({ keys: 'return' });
                        } finally {
                            sf.clipboard.setText({ text: oldClipboardText });
                        }
                    }
                }
                
                function main() {
                    //Activate and invalidate Pro Tools main window 
                    sf.ui.proTools.appActivateMainWindow();
                
                    //Recall Window Configuration
                    sf.ui.proTools.menuClick({
                        menuPath: ["Window", "Configurations", windowConfigurationName],
                    });
                
                    //Invalidate Pro Tools main window after window configuration change
                    sf.ui.proTools.mainWindow.invalidate();
                
                    //Copy selected Clip(s) to clipboard.
                    sf.ui.proTools.menuClick({ menuPath: ["Edit", "Copy"], });
                
                    const guideTrack = sf.ui.proTools.trackGetByName({ name: guideTrackName, makeVisible: true }).track;
                
                    //The guide track may be added to the main window, if so, invalidate is needed.
                    sf.ui.proTools.mainWindow.invalidate();
                
                    //Select and Make Visible guide track
                    guideTrack.trackSelect();
                
                    //Paste clips to guide track.
                    sf.ui.proTools.menuClick({ menuPath: ["Edit", "Paste"], });
                
                    //Open VisLM2 and Analyse the loudnes of the selection.
                    measureClipLoudness();
                
                    //Prompt user for Loudness value
                    const measuredLoudnessValue = sf.interaction.displayDialog({
                        title: "Loudness",
                        prompt: "Please enter the measured loudness value",
                        buttons: ["Cancel", "Submit"],
                        cancelButton: "Cancel",
                        defaultButton: "Submit",
                        defaultAnswer: ""
                    }).text;
                
                    //Calculate the loudness difference
                    const loudnessDifference = (Number(targetLoudnessValue) - Number(measuredLoudnessValue)).toFixed(1);
                
                    //Re-activate Pro Tools main window
                    sf.ui.proTools.appActivateMainWindow()
                
                    //Set Guide Track to "touch" & "Trim"
                    if (!guideTrack.automationModeButton.value.invalidate().value.includes("touch")) {
                        guideTrack.automationModeSet({ automationModeName: "touch", });
                    }
                
                    //Set Guide Track to "touch" & "Trim"
                    if (!guideTrack.automationModeButton.value.invalidate().value.includes("trim")) {
                        guideTrack.automationModeSet({ automationModeName: "trim", });
                    }
                
                    //Ensure that the Pro Tools Automation window is open.
                    sf.ui.proTools.automationWindowRequireOpenAutomationWindow();
                
                    //Enable Automation Preview
                    sf.ui.proTools.automationPreview({
                        targetValue: "Enable"
                    });
                
                    const guitdeTrackFloatingOutputWindow = sf.ui.proTools.mainTrackOutputWindow.buttons.whoseTitle.is("Track selector\n" + guideTrackName).first;
                
                    //Open guide track's floating output fader window
                    if (!guitdeTrackFloatingOutputWindow.exists) {
                        guideTrack.trackOutputToggleShow();
                    }
                
                    //Wait for floating output fader window.
                    guitdeTrackFloatingOutputWindow.elementWaitFor();
                
                    const outputVolumeNumericalField = sf.ui.proTools.mainTrackOutputWindow.textFields.whoseTitle.is('Volume Numerical').first;
                
                    //Click the output fader volume's numerical input field
                    setNumberFieldValue({
                        numberField: outputVolumeNumericalField,
                        targetValue: loudnessDifference,
                    });
                
                    //Write automation to selection and clear
                    sf.ui.proTools.automationWriteAutoToSelectionAndClear();
                
                    //Deactivate Trim Automation mode on track
                    if (guideTrack.automationModeButton.value.invalidate().value.includes("trim")) {
                        guideTrack.automationModeSet({ automationModeName: "Trim", });
                    }
                
                    //Coalesce Volume Automation to Clip Gain
                    sf.ui.proTools.menuClick({
                        menuPath: ["Edit", "Automation", "Coalesce Volume Automation to Clip Gain"],
                    });
                
                    //Close guide track's floating output fader window
                    if (sf.ui.proTools.mainTrackOutputWindow.buttons.whoseTitle.is("Track selector\n" + guideTrackName).first.exists) {
                        guideTrack.trackOutputToggleShow();
                    }
                
                    //Log loudness adjustment
                    log(`The loudness was adjusted by ${loudnessDifference}`);
                
                    //Recall Window Configuration
                    sf.ui.proTools.menuClick({
                        menuPath: ["Window", "Configurations", windowConfigurationName],
                    });
                
                    //Invalidate Pro Tools main window after window configuration change
                    sf.ui.proTools.mainWindow.invalidate();
                }
                
                main();
                

                Note: It looks like you are on Mac OS 10.13, and Pro Tools 2020.12. I'm unable to test these versions as my current systems are on Catalina and Monterey. So let me know if the issue continues and I'll dig deeper.

                Rock on.

                1. RRandall Smith @Randall_Smith
                    2022-10-10 21:32:17.958Z

                    You are correct. We are stuck on 2020.12 because on 10.15 and above, when Pro Tools bounces out an HD Pro Res video it changes the color space from REC 709 to REC 601. We generate AirMaster video files out of our audio sessions, so we have to wait until they fix that.

                    So, first let me thank you for this. You had to change quite a bit on this and I am sorry for that. There is an error that I happening:
                    Element was not found or removed after waiting 2000 ms (Pro Tools - Level Guide Track - v2: Line 124). The window does pop up though, so I am not sure yet why it is failing out. It doesn't try to enter a value to lower the fader.

                    Randall

                    1. Kitch Membery @Kitch2022-10-10 21:45:25.374Z

                      My pleasure Randall.

                      Ah yeah that's unfortunate that it changes the color space.

                      I'll take a look at the script shortly to see if I can resolve the bug. Thanks for your patience.

                      Rock on!

                      1. In reply toRandall_Smith:
                        Kitch Membery @Kitch2022-10-10 23:29:43.091Z

                        Hi Randall,

                        Can you give this a try...

                        const guideTrackName = "Guide Track";
                        const targetLoudnessValue = -24.1;
                        const windowConfigurationName = "1: Blank";
                        
                        
                        function measureClipLoudness() {
                            //Open the Vis LM2 AudioSuite window
                            const visLm2Window = sf.ui.proTools.audioSuiteOpenPlugin({
                                category: "Sound Field",
                                name: "NUGEN VisLM2",
                            }).window;
                        
                            //Wait for Vis LM2 AudioSuite window
                            visLm2Window.elementWaitFor();
                        
                            //Analyse the selection
                            visLm2Window.buttons.whoseTitle.is('Analyze').first.elementClick();
                        
                            //Wait for Analysis to finish
                            sf.ui.proTools.waitForNoModals();
                        }
                        
                        /** @param {{numberField:AxElement, targetValue: string}} args */
                        function setNumberFieldValue({ numberField, targetValue }) {
                            if (numberField.value.invalidate().value.trim() !== targetValue) {
                        
                                const oldClipboardText = sf.clipboard.getText().text;
                        
                                try {
                                    const text = targetValue;
                                    sf.clipboard.setText({ text: text });
                        
                                    numberField.elementClick();
                        
                                    sf.keyboard.press({ keys: "cmd+v", });
                        
                                    var i = 0;
                        
                                    do {
                                        sf.wait({ intervalMs: 1 });
                                        i++
                        
                                        if (i >= 5) { throw `Could not update the number field` }
                                    } while (numberField.value.invalidate().value !== targetValue);
                        
                                    sf.keyboard.press({ keys: 'return' });
                                } finally {
                                    sf.clipboard.setText({ text: oldClipboardText });
                                }
                            }
                        }
                        
                        function main() {
                            //Activate and invalidate Pro Tools main window 
                            sf.ui.proTools.appActivateMainWindow();
                        
                            //Recall Window Configuration
                            sf.ui.proTools.menuClick({
                                menuPath: ["Window", "Configurations", windowConfigurationName],
                            });
                        
                            //Invalidate Pro Tools main window after window configuration change
                            sf.ui.proTools.mainWindow.invalidate();
                        
                            //Copy selected Clip(s) to clipboard.
                            sf.ui.proTools.menuClick({ menuPath: ["Edit", "Copy"], });
                        
                            const guideTrack = sf.ui.proTools.trackGetByName({ name: guideTrackName, makeVisible: true }).track;
                        
                            //The guide track may be added to the main window, if so, invalidate is needed.
                            sf.ui.proTools.mainWindow.invalidate();
                        
                            //Select and Make Visible guide track
                            guideTrack.trackSelect();
                        
                            //Paste clips to guide track.
                            sf.ui.proTools.menuClick({ menuPath: ["Edit", "Paste"], });
                        
                            //Open VisLM2 and Analyse the loudnes of the selection.
                            measureClipLoudness();
                        
                            //Prompt user for Loudness value
                            const measuredLoudnessValue = sf.interaction.displayDialog({
                                title: "Loudness",
                                prompt: "Please enter the measured loudness value",
                                buttons: ["Cancel", "Submit"],
                                cancelButton: "Cancel",
                                defaultButton: "Submit",
                                defaultAnswer: ""
                            }).text;
                        
                            //Calculate the loudness difference
                            const loudnessDifference = (Number(targetLoudnessValue) - Number(measuredLoudnessValue)).toFixed(1);
                        
                            //Re-activate Pro Tools main window
                            sf.ui.proTools.appActivateMainWindow()
                        
                            //Set Guide Track to "touch" & "Trim"
                            if (!guideTrack.automationModeButton.value.invalidate().value.includes("touch")) {
                                guideTrack.automationModeSet({ automationModeName: "touch", });
                            }
                        
                            //Set Guide Track to "touch" & "Trim"
                            if (!guideTrack.automationModeButton.value.invalidate().value.includes("trim")) {
                                guideTrack.automationModeSet({ automationModeName: "trim", });
                            }
                        
                            //Ensure that the Pro Tools Automation window is open.
                            sf.ui.proTools.automationWindowRequireOpenAutomationWindow();
                        
                            //Enable Automation Preview
                            sf.ui.proTools.automationPreview({
                                targetValue: "Enable"
                            });
                        
                            const guitdeTrackFloatingOutputWindowTitleBtn = sf.ui.proTools.mainTrackOutputWindow.invalidate().buttons.whoseTitle.is("Track selector\n" + guideTrackName).first;
                        
                            //Open guide track's floating output fader window
                            if (!guitdeTrackFloatingOutputWindowTitleBtn.exists) {
                                guideTrack.trackOutputToggleShow();
                            }
                        
                            //Wait for floating output fader window.
                            guitdeTrackFloatingOutputWindowTitleBtn.elementWaitFor();
                        
                            const outputVolumeNumericalField = sf.ui.proTools.mainTrackOutputWindow.invalidate().textFields.whoseTitle.is('Volume Numerical').first;
                        
                            //Click the output fader volume's numerical input field
                            setNumberFieldValue({
                                numberField: outputVolumeNumericalField,
                                targetValue: loudnessDifference,
                            });
                        
                            //Write automation to selection and clear
                            sf.ui.proTools.automationWriteAutoToSelectionAndClear();
                        
                            //Deactivate Trim Automation mode on track
                            if (guideTrack.automationModeButton.value.invalidate().value.includes("trim")) {
                                guideTrack.automationModeSet({ automationModeName: "Trim", });
                            }
                        
                            //Coalesce Volume Automation to Clip Gain
                            sf.ui.proTools.menuClick({
                                menuPath: ["Edit", "Automation", "Coalesce Volume Automation to Clip Gain"],
                            });
                        
                            //Close guide track's floating output fader window
                            if (sf.ui.proTools.mainTrackOutputWindow.buttons.whoseTitle.is("Track selector\n" + guideTrackName).first.exists) {
                                guideTrack.trackOutputToggleShow();
                            }
                        
                            //Log loudness adjustment
                            log(`The loudness was adjusted by ${loudnessDifference}`);
                        
                            //Recall Window Configuration
                            sf.ui.proTools.menuClick({
                                menuPath: ["Window", "Configurations", windowConfigurationName],
                            });
                        
                            //Invalidate Pro Tools main window after window configuration change
                            sf.ui.proTools.mainWindow.invalidate();
                        }
                        
                        main();
                        

                        You may need to have the "Suppress Automation "write to..." Warnings" checkbox enabled in the Pro Tools Preferences => Mixing => Automation panel, for this to work.

                        1. RRandall Smith @Randall_Smith
                            2022-10-14 13:49:31.593Z

                            Thank you, but it still jumps to a random track.

                            1. @Kitch and @Randall_Smith – it might be worth it to try to isolate the part of this script that causes the random track selection. That should speed up this process :)

                              Please note that this is still using Window configurations, which I won't recommend. It's better to use SoundFlow to close, move windows as necessary.

                              Randall, are there cases where the guide track might not be scrolled to / not be visible? I don't see a trackScrollToView anywhere, but the automationModeSet commands are simulating mouse clicks (if HUI is not set up), so this might be needed.

                              1. If this doesn't help, Kitch might need to see a screen recording of this happening to further help isolate it - but I'll let you two take that part.

                              2. In reply toRandall_Smith:
                                Kitch Membery @Kitch2022-10-14 19:05:53.472Z

                                @chrscheuer, good call.

                                I'll make some adjustments to the script to remove the Window Configurations, and add a trackScrollToView.

                                If that does not work I'll isolate the issue and see if we can work out what is going on. :-)

                                1. In reply toRandall_Smith:
                                  Kitch Membery @Kitch2022-10-14 19:39:52.139Z

                                  Hi @Randall_Smith

                                  In this iteration of the script, at Christians suggestion, I have removed the Windows Configurations, and have moved the AudioSuite plugin to the center of the screen. I've also added a trackScroll to view in case that was causing an issue.

                                  const guideTrackName = "Guide Track";
                                  const targetLoudnessValue = -24.1;
                                  const windowConfigurationName = "1: Blank";
                                  
                                  function moveAudioSuiteWindow({ audioSuiteWindow }) {
                                      const mainWindowFrame = sf.ui.proTools.mainWindow.frame;
                                  
                                      audioSuiteWindow.windowMove({
                                          position: {
                                              x: mainWindowFrame.w / 2 - audioSuiteWindow.frame.w / 2,
                                              y: mainWindowFrame.h / 2 - audioSuiteWindow.frame.h / 2
                                          },
                                      });
                                  }
                                  
                                  function measureClipLoudness() {
                                      //Open the Vis LM2 AudioSuite window
                                      const visLm2Window = sf.ui.proTools.audioSuiteOpenPlugin({
                                          category: "Sound Field",
                                          name: "NUGEN VisLM2",
                                      }).window;
                                  
                                      //Wait for Vis LM2 AudioSuite window
                                      visLm2Window.elementWaitFor();
                                  
                                      //Center the AudioSuite Window
                                      moveAudioSuiteWindow({
                                          audioSuiteWindow: visLm2Window
                                      });
                                  
                                      //Analyse the selection
                                      visLm2Window.buttons.whoseTitle.is('Analyze').first.elementClick();
                                  
                                      //Wait for Analysis to finish
                                      sf.ui.proTools.waitForNoModals();
                                  }
                                  
                                  /** @param {{numberField:AxElement, targetValue: string}} args */
                                  function setNumberFieldValue({ numberField, targetValue }) {
                                      if (numberField.value.invalidate().value.trim() !== targetValue) {
                                  
                                          const oldClipboardText = sf.clipboard.getText().text;
                                  
                                          try {
                                              const text = targetValue;
                                              sf.clipboard.setText({ text: text });
                                  
                                              numberField.elementClick();
                                  
                                              sf.keyboard.press({ keys: "cmd+v", });
                                  
                                              var i = 0;
                                  
                                              do {
                                                  sf.wait({ intervalMs: 1 });
                                                  i++
                                  
                                                  if (i >= 5) { throw `Could not update the number field` }
                                              } while (numberField.value.invalidate().value !== targetValue);
                                  
                                              sf.keyboard.press({ keys: 'return' });
                                          } finally {
                                              sf.clipboard.setText({ text: oldClipboardText });
                                          }
                                      }
                                  }
                                  
                                  function main() {
                                      //Activate and invalidate Pro Tools main window 
                                      sf.ui.proTools.appActivateMainWindow();
                                      sf.ui.proTools.mainWindow.invalidate();
                                  
                                      //Get windows whose title does not start with "Edit: "
                                      const nonEditWindows = sf.ui.proTools.windows.filter(win => !win.title.invalidate().value.startsWith("Edit: "))
                                  
                                      //Close all windows whose title does not start with "Edit: "
                                      nonEditWindows.forEach(win => win.windowClose());
                                  
                                      //Copy selected Clip(s) to clipboard.
                                      sf.ui.proTools.menuClick({ menuPath: ["Edit", "Copy"], });
                                  
                                      let guideTrack = sf.ui.proTools.trackGetByName({ name: guideTrackName, makeVisible: true }).track;
                                  
                                      //The guide track may be added to the main window, if so, invalidate is needed.
                                      sf.ui.proTools.mainWindow.invalidate();
                                  
                                      //Scroll "Guide Track" into view
                                      guideTrack.trackScrollToView();
                                  
                                      //Select and Make Visible guide track
                                      guideTrack.trackSelect();
                                  
                                      //Paste clips to guide track.
                                      sf.ui.proTools.menuClick({ menuPath: ["Edit", "Paste"], });
                                  
                                      //Open VisLM2 and Analyse the loudnes of the selection.
                                      measureClipLoudness();
                                  
                                      //Prompt user for Loudness value
                                      const measuredLoudnessValue = sf.interaction.displayDialog({
                                          title: "Loudness",
                                          prompt: "Please enter the measured loudness value",
                                          buttons: ["Cancel", "Submit"],
                                          cancelButton: "Cancel",
                                          defaultButton: "Submit",
                                          defaultAnswer: ""
                                      }).text;
                                  
                                      //Calculate the loudness difference
                                      const loudnessDifference = (Number(targetLoudnessValue) - Number(measuredLoudnessValue)).toFixed(1);
                                  
                                      //Re-activate Pro Tools main window
                                      sf.ui.proTools.appActivateMainWindow()
                                  
                                      //Set Guide Track to "touch" & "Trim"
                                      if (!guideTrack.automationModeButton.value.invalidate().value.includes("touch")) {
                                          guideTrack.automationModeSet({ automationModeName: "touch", });
                                      }
                                  
                                      //Set Guide Track to "touch" & "Trim"
                                      if (!guideTrack.automationModeButton.value.invalidate().value.includes("trim")) {
                                          guideTrack.automationModeSet({ automationModeName: "trim", });
                                      }
                                  
                                      //Ensure that the Pro Tools Automation window is open.
                                      sf.ui.proTools.automationWindowRequireOpenAutomationWindow();
                                  
                                      //Enable Automation Preview
                                      sf.ui.proTools.automationPreview({
                                          targetValue: "Enable"
                                      });
                                  
                                      const guitdeTrackFloatingOutputWindowTitleBtn = sf.ui.proTools.mainTrackOutputWindow.invalidate().buttons.whoseTitle.is("Track selector\n" + guideTrackName).first;
                                  
                                      //Open guide track's floating output fader window
                                      if (!guitdeTrackFloatingOutputWindowTitleBtn.exists) {
                                          guideTrack.trackOutputToggleShow();
                                      }
                                  
                                      //Wait for floating output fader window.
                                      guitdeTrackFloatingOutputWindowTitleBtn.elementWaitFor();
                                  
                                      const outputVolumeNumericalField = sf.ui.proTools.mainTrackOutputWindow.invalidate().textFields.whoseTitle.is('Volume Numerical').first;
                                  
                                      //Click the output fader volume's numerical input field
                                      setNumberFieldValue({
                                          numberField: outputVolumeNumericalField,
                                          targetValue: loudnessDifference,
                                      });
                                  
                                      //Write automation to selection and clear
                                      sf.ui.proTools.automationWriteAutoToSelectionAndClear();
                                  
                                      //Deactivate Trim Automation mode on track
                                      if (guideTrack.automationModeButton.value.invalidate().value.includes("trim")) {
                                          guideTrack.automationModeSet({ automationModeName: "Trim", });
                                      }
                                  
                                      //Coalesce Volume Automation to Clip Gain
                                      sf.ui.proTools.menuClick({
                                          menuPath: ["Edit", "Automation", "Coalesce Volume Automation to Clip Gain"],
                                      });
                                  
                                      //Close guide track's floating output fader window
                                      if (sf.ui.proTools.mainTrackOutputWindow.buttons.whoseTitle.is("Track selector\n" + guideTrackName).first.exists) {
                                          guideTrack.trackOutputToggleShow();
                                      }
                                  
                                      //Log loudness adjustment
                                      log(`The loudness was adjusted by ${loudnessDifference}`);
                                  }
                                  
                                  main();
                                  

                                  If the above script still continues to select a random track, try creating a new script and add the following code. If this script does not select and scroll to the guide track let me know.;

                                  const guideTrackName = "Guide Track";
                                  
                                  sf.ui.proTools.appActivateMainWindow();
                                  sf.ui.proTools.mainWindow.invalidate();
                                  
                                  const guideTrack = sf.ui.proTools.trackGetByName({ name: guideTrackName, makeVisible: true }).track;
                                  
                                  guideTrack.trackScrollToView();
                                  guideTrack.trackSelect();
                                  

                                  Thanks for your patience Randall :-)