No internet connection
  1. Home
  2. How to

Pro Tools 24.10.2 - access the Tracks List

By Randall Smith @Randall_Smith
    2025-01-15 16:35:23.359Z

    Hello, I am porting a script that worked prior to PT.24.3.1.

    This script would take parts of an AAF, count the number of tracks, select the correct number of tracks in a specific template and copy the audio down.

    In PT 24.10.2, if fails out because it cannot select the destination tracks in the Track Selection window (line 55 in the script). SF gives an error message that LinkTrack and Edit Selection is off, which is not the case.

    Here is the script:

    const aafFileTypes = ['DX', 'MX', 'FX - Mono', 'FX - Stereo', 'GX']
    var startingVisibleTrackCount = 8
    var selectedTrackCount = sf.ui.proTools.selectedTrackCount;
    const originalTracks = sf.ui.proTools.selectedTrackNames;
    
    let selectedTrackType = sf.interaction.popupSearch({
        items: aafFileTypes.map(p => ({ name: p, })),
    }).item.name;
    
    var selTrack = selectedTrackType;
    
    //alert("You selected this : \r" + selTrack);
    
    if (selTrack == 'DX') {
        var starterTrack = 'DX A'
        var monoToStereoNumber = (selectedTrackCount);
        var batchRenamePrest = "Raname - DX"
    
    } else if (selTrack == 'MX') {
        var starterTrack = '[MX] A'
        var monoToStereoNumber = (selectedTrackCount / 2);
        var batchRenamePrest = "Raname - MX"
    
    } else if (selTrack == 'FX - Mono') {
        var starterTrack = '[FX] mA'
        var monoToStereoNumber = (selectedTrackCount);
        var batchRenamePrest = "Raname - FX m"
        alert("If moving more than four tracks worth of Mono Effects - Please take this opportunity to unhide FX mE - H.")
    
    } else if (selTrack == 'FX - Stereo') {
        var starterTrack = '[FX] sA'
        var monoToStereoNumber = (selectedTrackCount / 2);
        var batchRenamePrest = "Raname - FX st"
    
    } else if (selTrack == 'GX') {
        var starterTrack = '[GX] sA'
        var monoToStereoNumber = (selectedTrackCount / 2);
        var batchRenamePrest = "Raname - GX st"
    
    } else {
    
    }
    
    var repNumber = (monoToStereoNumber - 1);
    var tracksToAdd = (monoToStereoNumber - startingVisibleTrackCount);
    
    function selectTrackDelta(delta, trackToSelect) {
        sf.ui.proTools.appActivateMainWindow();
        let destinationTrackArray = []
    
        sf.ui.proTools.trackSelectByName({
            names: [trackToSelect],
            deselectOthers: true,
        });
        sf.ui.proTools.selectedTrack.trackScrollToView();
    
        sf.keyboard.press({
            keys: "semicolon",
            repetitions: repNumber,
        });
        sf.ui.proTools.trackSelectByName({
            names: [trackToSelect],
            deselectOthers: true,
        });
        sf.ui.proTools.selectedTrack.trackScrollToView();
        destinationTrackArray.push(sf.ui.proTools.selectedTrackNames[0])
        for (let i = 0; i < repNumber; i++) {
    
            sf.keyboard.press({
                keys: "semicolon",
                repetitions: 1,
            });
            var trackImOn = sf.ui.proTools.selectedTrackNames[0];
            destinationTrackArray.push(trackImOn)
        }
        const firstSelectedTrackName = sf.ui.proTools.selectedTrackNames[0];
        const visibleTrackNames = sf.ui.proTools.visibleTrackNames;
        const visibleTrackIndex = visibleTrackNames.findIndex(n => n === firstSelectedTrackName);
        if (visibleTrackIndex < 0) return;
    
        let newTrackIndex = visibleTrackIndex + delta;
        if (newTrackIndex < 0) newTrackIndex = 0;
        if (newTrackIndex >= visibleTrackNames.length) newTrackIndex = visibleTrackNames.length - 1;
    
        sf.ui.proTools.trackSelectByName({
            names: [visibleTrackNames[newTrackIndex]], deselectOthers: false,
        });
    
        sf.ui.proTools.trackSelectByName({ names: destinationTrackArray })
    }
    
    function duplicateTracks(delta, trackToSelect) {
        sf.ui.proTools.appActivateMainWindow();
    
        sf.ui.proTools.trackSelectByName({
            names: [trackToSelect],
            deselectOthers: true,
        });
    
        sf.ui.proTools.trackDuplicateSelected({
            numberOfDuplicates: delta,
        });
    }
    
    function batchRename(batchPreset) {
    
        sf.ui.proTools.appActivateMainWindow();
        sf.ui.proTools.selectedTrack.titleButton.popupMenuSelect({
            isRightClick: true,
            menuPath: ['Batch Rename...']
        });
        sf.ui.proTools.windows.whoseTitle.is("Batch Track Rename").first.elementWaitFor();
    
        sf.ui.proTools.windows.whoseTitle.is("Batch Track Rename").first.children.whoseRole.is("AXMenuButton").whoseTitle.is("Librarian menu").first.popupMenuSelect({
            menuPath: [batchPreset],
        });
    
        sf.ui.proTools.windows.whoseTitle.is("Batch Track Rename").first.buttons.whoseTitle.is("OK").first.elementClick();
    }
    
    function pasteContents(needToRename, batchPreset) {
        sf.wait();
        sf.ui.proTools.menuClick({
            menuPath: ["Edit", "Copy"],
        });
        sf.keyboard.press({
            keys: "cmd+c",
        });
    
    
        selectTrackDelta(repNumber, starterTrack);
    
        sf.ui.proTools.selectedTrack.trackScrollToView();
    
        sf.wait();
        sf.ui.proTools.menuClick({
            menuPath: ["Edit", "Paste"],
        });
        
            sf.keyboard.press({
            keys: "cmd+v",
        });
        sf.wait();
    
        if (needToRename == 'true') {
            batchRename(batchPreset)
        }
    
        //Release all modifiers
        //  sf.keyboard.modifiers();
        sf.ui.proTools.trackSelectByName({ names: originalTracks });
    
        sf.ui.proTools.selectedTrack.trackScrollToView();
    
        sf.ui.proTools.trackSelectByName({ names: originalTracks });
    
        // sf.ui.proTools.trackHideAndMakeInactiveSelected();
    }
    
    if (monoToStereoNumber > startingVisibleTrackCount) {
        log("You Need More Tracks");
        var needToRename = 'true'
    
        sf.ui.proTools.menuClick({
            menuPath: ["Edit", "Copy"],
        });
    
        var deltaTracks = (selectedTrackCount - startingVisibleTrackCount);
        var deltaTracks = parseInt(deltaTracks, 10);
        var deltaTracks = (deltaTracks - 1);
    
        sf.ui.proTools.appActivateMainWindow();
    
        sf.ui.proTools.trackSelectByName({
            names: [starterTrack],
            deselectOthers: true,
        });
    
        sf.keyboard.press({
            keys: "semicolon",
            repetitions: deltaTracks,
        });
    
        duplicateTracks(tracksToAdd, starterTrack);
    
        pasteContents(needToRename, batchRenamePrest);
    
    } else {
        log("Good to Go")
        var needToRename = 'false'
        pasteContents(needToRename, batchRenamePrest);
    
    
    }
    

    Help would be appreciated,
    -Randall

    • 4 replies
    1. Kitch Membery @Kitch2025-01-15 21:04:46.363Z

      Hi @Randall_Smith,

      In point form, can I get you list the manual steps that the script is meant to perform?

      And maybe provide a before and after screenshot to show the result.

      Thanks in advance. :-)

      1. RRandall Smith @Randall_Smith
          2025-01-15 21:17:54.679Z

          Sure,

          1.) user selects tracks to move (i.e. 3 mono dialogue tracks from an AAF). SF has Pro Tools copy the track contents into memory
          2.) A sf.popup window comes up asking the user to choose where those tracks go (ie, DX, MX, mono SFX, st SFX)
          3.) SF counts the number of selected tracks and checks it against the defaults that our promo mixing template has visible at the start.
          4.) SF selects the name of the first visible track for a selected food group (ie DX A). SF will then select the correct number of subsequent tracks to match the number of tracks selected in step 1. If the number of required tracks exceeds the number of visible tracks, SF will duplicate a blank track 'x' number of times (where x is the difference between required tracks and visible tracks) and rename the tracks to match our naming convention. (I see that there is a spelling error here - d'Oh). SF will then reselect all of the destination/visible tracks that are needed.
          5.) SF will have Pro Tools paste the contents of the clipboard onto the destination tracks.
          6.) (optional) SF will have PT reselect the source tracks and select 'Hide and Make Inactive'

          Currently, it is failing at step 4. (whereas this would work in Pro Tools Prior to 24.3.1). It is in the 'selectTrackDelta' function at :
          sf.ui.proTools.selectedTrack.trackScrollToView();

          the SF log gives me this:
          No track selected (in Track List View)
          Consider turning on Link Edit and Track Selection (AAF - Move Clips to correct LOC.: Line 55)

          1. Kitch Membery @Kitch2025-01-15 21:47:10.706Z

            Thanks for that @Randall_Smith,

            I'll take a look at this when I have a moment.

            1. In reply toRandall_Smith:
              Kitch Membery @Kitch2025-01-15 22:53:10.147Z

              This looks as though it may be fixed by invalidating Pro Tools' Main Window at the top of the script.

              Add this at the top of your script.

              sf.ui.proTools.mainWindow.invalidate();
              

              Let me know if that fixes the issue. :-)