No internet connection
  1. Home
  2. How to

Pull Track Presets into a popupSearch list

By Mike Wax @mikewax
    2023-03-18 02:12:45.798Z

    Hello SF community!

    Looks like I'm stuck on another script today...

    So i'm trying to get my Track Presets into a popupSearch interaction, but I'm having troubles pulling the list.

    In my attempts to make this more universal, I want to be able to select which track preset i want to import, hence the list idea. So I'm attempting to pull it from the New Tracks window, but it's not working out.

    I have no problem having more than one popupSearch dialogue, one for each level to go into (unless the popupSearch allows for folders/nesting/multiple levels).

    Here's my current code. The log() at the end only pulls null and i'm out of ideas.
    Thanks for the help!!

    
    // Activate Pro Tools.
    sf.ui.proTools.appActivateMainWindow();
    
    // Get all the track names in the session.
    const allTracks = sf.ui.proTools.trackGetAllTracks().names;
    
    // Generate a list of all the tracks to determine where you want the track preset to be inserted.
    let selectTrack = sf.interaction.popupSearch({
        title: "Which track would you like the Track Preset to be inserted after?",
        items: allTracks.map(tr => ({ name: tr, path: tr })),
        onCancel: "Abort"
    }).item.path;
    
    // Selects the track.
    sf.ui.proTools.trackSelectByName({
        names: [selectTrack],
        deselectOthers: true
    });
    
    // Create Track Preset.
    sf.ui.proTools.menuClick({
        menuPath: ["Track", "New..."]
    });
    
    const trackPresetList = sf.ui.proTools.windows.whoseTitle.is("New Tracks").first.popupButtons.allItems[1].popupMenuFetchAllItems();
    const presetMenuItems = trackPresetList.menuItems;
    const trackPresetSelection = presetMenuItems.map(preset => preset["Names"[0]]);
    
    log(presetMenuItems);
    
    

    Here is my Track Preset hierarchy. I need access to "Scorpion" and the options should be "SFX" or Jingles" and then there are options inside there that need to be in a list as well.

    Solved in post #3, click to view
    • 3 replies
    1. you were pretty close. You had an end bracket in the wrong position.
      Line 28 should be:

      const trackPresetSelection = presetMenuItems.map(preset => preset["Names"][0])
      
      1. In reply tomikewax:

        this might work for you. just change the preset menu path to ["Track Presets", "Scorpion", "Jingles"] or whatever…

        const presetMenuPath = ["Track Presets", "Avid"]
        
        // Activate Pro Tools.
        sf.ui.proTools.appActivateMainWindow();
        
        // Get all the track names in the session.
        const allTracks = sf.ui.proTools.trackGetAllTracks().names;
        
        // Generate a list of all the tracks to determine where you want the track preset to be inserted.
        let selectTrack = sf.interaction.popupSearch({
            title: "Which track would you like the Track Preset to be inserted after?",
            items: allTracks.map(tr => ({ name: tr, path: tr })),
            onCancel: "Abort"
        }).item.path;
        
        // Selects the track.
        sf.ui.proTools.trackSelectByName({
            names: [selectTrack],
            deselectOthers: true
        });
        
        // Create Track Preset.
        sf.ui.proTools.menuClick({
            menuPath: ["Track", "New..."]
        });
        
        // Make reference to new track dialog window
        const newTrackDlgWin = sf.ui.proTools.windows.whoseTitle.is("New Tracks").first;
        
        // Wait for new track dialog
        newTrackDlgWin.elementWaitFor()
        
        // Get Menu Items
        const trackTypes = sf.ui.proTools.windows.whoseTitle.is("New Tracks").first.popupButtons.allItems[1].popupMenuFetchAllItems();
        const trackTypePaths = trackTypes.menuItems.map(items => items["Path"])
        
        // Filter Menu Entry items with paths that contain all elements of `presetMenuPath`
        const tracktrackTypePathselection = trackTypePaths.filter(item => presetMenuPath.every(p => (item.includes(p))));
        
        // Have user select preset path
        const userSelectedPath = JSON.parse(sf.interaction.popupSearch({
            title: "Which preset directory?",
            items: tracktrackTypePathselection.map(path => ({ name: JSON.stringify(path), path: JSON.stringify(path) })),
            onCancel: "Abort"
        }).item.path)
        
        // Select path for first New Tracks window popup menu
        const newTracksMenu1 = sf.ui.proTools.windows.whoseTitle.is("New Tracks").first.popupButtons.allItems[1]
        newTracksMenu1.popupMenuSelect({
            menuPath: userSelectedPath
        })
        
        //Get Preset Names
        const popup2MenuItems = newTrackDlgWin.popupButtons.first.popupMenuFetchAllItems()
        const presetNames = popup2MenuItems.menuItems.map(item => item["Names"][0]);
        
        const userSelectedPreset = sf.interaction.popupSearch({
            title: "Which preset?",
            items: presetNames.map(name => ({ name: name, path: name })),
            onCancel: "Abort"
        }).item.name
        
        // Select preset in New Tracks window
        newTrackDlgWin.popupButtons.first.popupMenuSelect({
            menuPath: [userSelectedPreset]
        })
        
        // Click "Create" to create track and close window
        newTrackDlgWin.buttons.whoseTitle.is("Create").first.elementClick();
        
        // Wait for New Tracks dialog window to disappear
        newTrackDlgWin.elementWaitFor({waitType:"Disappear"})
        
        Reply1 LikeSolution
        1. Mike Wax @mikewax
            2023-03-19 02:20:42.205Z

            You're simply amazing, @Chris_Shaw!!!

            A few questions i have for you:

            1. What is the purpose of the JSON.parse and the JSON.stringify? Is that the same as using .toString?
            2. Does it matter whether you grab the Names or the Path? In line 35, you pull the "Path", but in line 55 you pull the "Names". When i log() the menuItems, the Path and the Names have the same content. Does it matter which one you use?
            3. The popup for the Directory shows the list still containing the brackets and quotes. Is there a way to be able to remove that so it just shows "SFX" or "Jingles"?

            My instinct is that it's showing up that way because the JSON.stringify is basically taking the preset path as a string, but when I try messing with it. I break things.

            I owe you many more beers.
            Thanks for taking the time to help out with this one as well.