No internet connection
  1. Home
  2. How to

Issue Writing Script Template

By Daniel Goodwin @Daniel_Goodwin
    2021-11-06 20:26:55.902Z2021-11-12 11:04:08.674Z

    Hey all. I'm trying to utilize a script template to recall track presets for Headphone Sends. My primary script works just fine, but then I tried converting it to a template, where each new preset selects a different recall setting. In this example, when I create a new script preset, I enter into the String{} container, the following:

    'Recall Track Presets', 'Avid', 'Headphones', 25-26' (or whatever numbers of the corresponding track preset

    I just can't seem to get it to complete the command, using the presets. It always hangs up on Line 12.

    Here is my template script:

    const menuPath = event.props.menuPath
    
    sf.ui.proTools.appActivateMainWindow();
    sf.ui.proTools.mainWindow.invalidate();
    var originallySelectedTrackNames = sf.ui.proTools.selectedTrackNames;
    function ensureFirstSelectedTrackIsVisible() {
        var originallySelectedTrackNames = sf.ui.proTools.selectedTrackNames;
        sf.ui.proTools.selectedTrack.trackScrollToView();
        sf.ui.proTools.trackSelectByName({ names: originallySelectedTrackNames, deselectOthers: true });
    }
    function recallTrackPreset() {
        sf.ui.proTools.selectedTrack.titleButton.popupMenuSelect({
            isRightClick: true,
            menuPath: []
        });
    }
    function main() {
        if (sf.ui.proTools.getMenuItem('Window', 'Mix').isMenuChecked) {
            sf.ui.proTools.menuClick({
                menuPath: ["Window", "Edit"],
                targetValue: "Enable",
            });
            ensureFirstSelectedTrackIsVisible()
            recallTrackPreset();
            sf.ui.proTools.menuClick({
                menuPath: ["Window", "Mix"],
                targetValue: "Enable",
            });
            sf.ui.proTools.trackSelectByName({ names: originallySelectedTrackNames, deselectOthers: true });
        }
        else {
            ensureFirstSelectedTrackIsVisible();
            recallTrackPreset();
            sf.ui.proTools.trackSelectByName({ names: originallySelectedTrackNames, deselectOthers: true });
        }
    }
    main();
    
    • 3 replies
    1. Hey Daniel,

      Quickly going over your script, the problem seems to lie on the popupMenuSelect() function inside recallTrackPreset(). The menuPath property of popupMenuSelect() is set to an empty array.

      The solution is simple though! Just get rid of the empty array and the menuPath property will inherit the value of the menuPath constant at the top of the script—which will yield the desired result. So basically, make the recallTrackPreset() function look like this:

      function recallTrackPreset() {
          sf.ui.proTools.selectedTrack.titleButton.popupMenuSelect({
              isRightClick: true,
              menuPath
          });
      }
      

      By the way, the following video will show you how to quote code here in the forum:
      https://www.youtube.com/watch?v=FRLCp6Sf9AI

      1. DDaniel Goodwin @Daniel_Goodwin
          2021-11-07 15:38:31.057Z

          Thank you for script quote tip!

          I tried as you said, and now Im getting the error: MenuPath or Menu Selector is required

          Not sure what I'm doing wrong here. I'm so sorry, I'm such a novice wirth code matters

          1. This indicates that nothing is passed in the menuPath property to the popupMenuSelect action. Make sure you're getting that from event.props and that the property has been filled out in your template.

            It would be easier to help if you share screenshots of your template setup, the preset you're running, and the full template script.