No internet connection
  1. Home
  2. How to

What obvious Syntax am I missing?

By Owen Granich-Young @Owen_Granich_Young
    2023-09-13 00:27:24.626Z

    Then 2nd if else line's 26-31 are not working... I can't figure out why. The IF works but the ELSE does not...

    Following script does as follows.
    Make a selection of any number of tracks, hold command and press button to set globalState remembering the selected tracks and copy the audio in the selection. This way I can grab a SFX from anywhere in my show and instead of worrying about what tracks it was spread across simply navigate to where I want and press paste. All was well and working great.

    I decided to get fancier with it in that if I highlighted a selection it would instead 'paste special' 'repeat to fill.' which works. But if it's not present the 'regular paste' else statment is not working... what am I dong wrong?

    function copy() {
        sf.ui.proTools.menuClick({ menuPath: ["Edit", "Copy"],});
    }
    
    function paste() {
        sf.ui.proTools.menuClick({ menuPath: ['Edit', 'Paste'] });
    }
    
    function pasteToFill() {
        sf.ui.proTools.menuClick({ menuPath: ["Edit", "Paste Special", "Repeat to Fill Selection"] });
    }
    
    
    sf.ui.proTools.mainWindow.invalidate();
    
    const repeatEnabled = sf.ui.proTools.getMenuItem("Edit", "Paste Special", "Repeat to Fill Selection").exists
    
    if (event.keyboardState.hasCommand) {
        /// Get Selected track names to variable
        globalState.selectedTracks = sf.ui.proTools.selectedTrackNames
        copy();
    } else {
        /// Re Select Tracks
        sf.ui.proTools.trackSelectByName({ names: globalState.selectedTracks })
        
        if (repeatEnabled) {
            pasteToFill();
        } else {
            log('why no paste')
            paste();
        }
    }
    

    I also built it this way just to take out the nested ELSE to see if that'd help but also no dice.

    function copy() {
        sf.ui.proTools.menuClick({ menuPath: ["Edit", "Copy"], });
    }
    
    function paste() {
        sf.ui.proTools.menuClick({ menuPath: ['Edit', 'Paste'] });
    }
    
    function pasteToFill() {
        sf.ui.proTools.menuClick({ menuPath: ["Edit", "Paste Special", "Repeat to Fill Selection"] });
    }
    
    
    sf.ui.proTools.mainWindow.invalidate();
    const repeatEnabled = sf.ui.proTools.getMenuItem("Edit", "Paste Special", "Repeat to Fill Selection").exists
    const modifierState = event.keyboardState.asString
    
    
    switch (modifierState) {
        case "cmd":
            /// Get Selected track names to variable
            globalState.selectedTracks = sf.ui.proTools.selectedTrackNames
            copy();
            break
        case "":
            /// Re Select Tracks
            sf.ui.proTools.trackSelectByName({ names: globalState.selectedTracks })
    
            if (repeatEnabled) {
                pasteToFill();
            } else {
                log('why no paste')
                paste();
            }
            break
    
    };
    

    What Obvious thing am I doing wrong?

    Solved in post #2, click to view
    • 3 replies
    1. Nathan Salefski @nathansalefski
        2023-09-13 17:57:42.506Z

        @Kitch relayed this message to me and it has saved me so much time in troubleshooting. How to use looseMatch in Popup Menu #post-14. Using this simple script I was able to determine the menu item exists regardless if you can select it or not:

        const repeatEnabled = sf.ui.proTools.getMenuItem(
            "Edit", 
            "Paste Special", 
            "Repeat to Fill Selection").exists
        
        if (repeatEnabled) {
            log('yes')
        } else {
            log('no')
        }
        
        Using this, I was able to determine if "Repeat to Fill Selection" was a valid selection option:
        const repeatEnabled = sf.ui.proTools.getMenuItem(
            "Edit", 
            "Paste Special", 
            "Repeat to Fill Selection").isEnabled
        
        if (repeatEnabled) {
            log('yes')
        } else {
            log('no')
        }
        

        Simply replace the .exists with .isEnabled in Line 15

        Reply4 LikesSolution
        1. I KNEW it was something dumb easy.
          Thanks boss.

          1. Nathan Salefski @nathansalefski
              2023-09-13 18:27:21.019Z

              I cannot tell you how many times I've spent days looking for a simple mistake lol