No internet connection
  1. Home
  2. How to

Selecting between 2 markers using marker names.

By Mike Wax @mikewax
    2020-10-11 22:27:40.788Z2020-10-12 19:45:35.030Z

    Referencing this post about selecting between 2 markers:

    Is there any way to make this work by using marker NAMES instead of number? I always use the same names for my markers, but sometimes they're not in the same position.

    Original code:

    function selectBetween(no1, no2)
    {
    
        sf.ui.proTools.memoryLocationsGoto({
            memoryLocationNumber: no1,
            restoreWindowOpenState: true,
            useKeyboard: true,
        });
    
        sf.ui.proTools.memoryLocationsGoto({
            extendSelection: true,
            memoryLocationNumber: no2,
            restoreWindowOpenState: true,
            useKeyboard: true,
        });
    
    }
    
    selectBetween(1, 4);
    

    I tried changing the selectBetween(1, 4) to selectBetween("START", "END") but it said it was invalid.
    As always, thank you for the help!

    Solved in post #2, click to view
    • 28 replies

    There are 28 replies. Estimated reading time: 37 minutes

    1. Try this :)

      
      function getMemoryLocations() {
      
          sf.ui.proTools.appActivate();
          sf.ui.proTools.mainWindow.elementRaise();
          var i = 0;
          while (i++ < 5) {
              if (!sf.ui.proTools.memoryLocationsWindow.invalidate().exists) {
                  sf.ui.proTools.getMenuItem('Window', 'Memory Locations').elementClick({}, 'Could not click to open Memory Locations window');
                  sf.ui.proTools.memoryLocationsWindow.elementWaitFor();
              }
              var table = sf.ui.proTools.memoryLocationsWindow.invalidate().tables.first;
              if (!table.exists) {
                  sf.ui.proTools.memoryLocationsWindow.windowClose();
              }
          }
          if (!table.exists) throw 'Could not find memory locations table';
          var seed = (new Date).valueOf();
          var items = [];
          table.children.forEach(function (item, i) {
              var num = item.children[0].children[0].title.value;
              var text = item.children[1].children[0].title.value;
              if (num === null || text === null) return;
              items.push({
                  num,
                  text,
              });
          });
          return items;
      }
      
      function selectBetweenMemoryLocationsByName({ name1, name2 }) {
          let locations = getMemoryLocations();
      
          let location1 = locations.find(l => l.text === name1);
          let location2 = locations.find(l => l.text === name2);
      
          if (!location1) throw `Could not find a memory location by name '${name1}'`;
          if (!location2) throw `Could not find a memory location by name '${name2}'`;
      
          let locNum1 = Number(location1.num.trim());
          let locNum2 = Number(location2.num.trim());
      
          sf.ui.proTools.memoryLocationsGoto({
              memoryLocationNumber: locNum1,
              useKeyboard: true,
          });
          sf.ui.proTools.memoryLocationsGoto({
              memoryLocationNumber: locNum2,
              extendSelection: true,
              useKeyboard: true,
          });
      }
      
      selectBetweenMemoryLocationsByName({
          name1: 'START',
          name2: 'END',
      });
      
      Reply2 LikesSolution
      1. Mike Wax @mikewax
          2020-10-13 04:49:41.942Z

          Per usual, this worked beautifully!! I wish i could understand what you did....lol.
          Thank you so much!!

          1. In reply tochrscheuer:
            TTristan Hoogland @Tristan
              2022-12-09 03:21:03.171Z

              Hey Chris // also Cc'ing you in @Kitch as per our chat the other week about this.

              I use this in one of my more elaborate scripts for printing mixes etc. It works amazingly 99% of the time, however, every so often it'll fail to work the way intended and flips out. If I'm remembering correctly when it does fail it seems to have trouble locating the specified memory locations, or at least selecting between them.

              I feel terrible not being able to provide a specific scenario where it's happening, but I'll try find some edge cases in the next few days to see if I can recreate it. A friend of mine using my script just told me it happened to him too. The error that he got was.

              "could not find memory location by name "START"
              he then recreated the marker and it resolved the START marker issue.
              then he had the same issue by the with END marker.

              Should we invalidating somewhere else in the markers window to make sure this doesn't happen? Or is there another way to do make a selection that's a bit more robust?

              Restarting soundflow didn't work.

              My feeling/memory is that it doesn't happen when the markers are created right before bouncing between them, but if the protools session already has them made from the start of the prep or mix that's when it has trouble finding them. I could be wrong about that, but that's my feeling. Maybe its a reload the protools session thing too. Again I'll try recreate it myself next chance I get.

              Thanks!

              1. Mike Wax @mikewax
                  2022-12-09 03:29:52.561Z

                  Hey @Tristan_Hoogland,

                  I'm wondering if there's a chance that it has to do with the number of the marker.

                  My START marker is always number 1, and END is always number 2. The script above references locNum1 and locNum2. Maybe that's what is throwing the error?

                  Now this is where @Kitch comes to save the day, seeing as how i would have no idea how to change that so it only references the NAME and not the LocNum.

                  Maybe test it out in a test session and make sure your markers are numbered properly and see if that fixes the error.

                  I too would love to know how this could be achieved!

                  I hope that helps a little.

                  1. TTristan Hoogland @Tristan
                      2022-12-09 03:38:34.337Z

                      Hey Mike!

                      I think it's generally been more robust when the markers are next to each other in the number, but then again it works in a lot of cases where that isn't the case too (which is why I LOVE this script) (i'm testing it right now and its working fine no matter what number they are - they can be 10 apart, or next to each other). I think Kitch is just using LocNum as a variable, doesn't seem to come up when i poke around in protools with the inspector thing.

                      Will keep trying to recreate!

                    • In reply toTristan:
                      Kitch Membery @Kitch2022-12-09 03:45:21.955Z

                      Hi @Tristan_Hoogland,

                      Will take a look at this tonight. In the mean time if you can reproduce the issue in a repeatable way that would be awesome. :-)

                      Rock on!

                      1. In reply toTristan:
                        Kitch Membery @Kitch2022-12-09 06:40:07.459Z

                        Hi @Tristan_Hoogland,

                        I had this script lying around, that gets the memory locations in a different way.

                        function getMemoryLocations() {
                            sf.ui.proTools.appActivateMainWindow();
                        
                            if (!sf.ui.proTools.memoryLocationsWindow.invalidate().exists) {
                                sf.ui.proTools.getMenuItem('Window', 'Memory Locations').elementClick({}, 'Could not click to open Memory Locations window');
                                sf.ui.proTools.memoryLocationsWindow.elementWaitFor();
                            }
                        
                            let table = sf.ui.proTools.memoryLocationsWindow.invalidate().tables.first;
                            if (!table.exists) throw 'Could not find memory locations table';
                        
                            let items = table.children.map(item => ({
                                num: item.children[0].children[0].title.value,
                                text: item.children[1].children[0].title.value,
                            }));
                        
                            return items;
                        }
                        
                        function selectBetweenMemoryLocationsByName({ name1, name2 }) {
                            let locations = getMemoryLocations();
                        
                            let location1 = locations.find(l => l.text === name1);
                            let location2 = locations.find(l => l.text === name2);
                        
                            if (!location1) throw `Could not find a memory location by name '${name1}'`;
                            if (!location2) throw `Could not find a memory location by name '${name2}'`;
                        
                            let locNum1 = Number(location1.num.trim());
                            let locNum2 = Number(location2.num.trim());
                        
                            sf.ui.proTools.memoryLocationsGoto({
                                memoryLocationNumber: locNum1,
                                useKeyboard: true,
                            });
                            sf.ui.proTools.memoryLocationsGoto({
                                memoryLocationNumber: locNum2,
                                extendSelection: true,
                                useKeyboard: true,
                            });
                        }
                        
                        selectBetweenMemoryLocationsByName({
                            name1: 'START',
                            name2: 'END',
                        });
                        

                        Obviously without being able to recreate the issue, it's difficult to know if this is the solution, but let me know if this works as expected. :-)

                        If you can get it to fail, It might be of useful getting a screenshot of the Memory Locations window just in case the settings for the table are setup differently.

                        Rock on!

                        1. In reply toTristan:
                          Kitch Membery @Kitch2022-12-09 07:10:53.308Z

                          @Tristan_Hoogland...

                          Here's a new and improved version.

                          function getMemoryLocations() {
                              sf.ui.proTools.appActivateMainWindow();
                          
                              let memoryLocationsWindow = sf.ui.proTools.memoryLocationsWindow;
                          
                              if (!memoryLocationsWindow.invalidate().exists) {
                                  sf.ui.proTools.getMenuItem('Window', 'Memory Locations')
                                      .elementClick({}, 'Could not click to open Memory Locations window');
                          
                                  sf.ui.proTools.memoryLocationsWindow.elementWaitFor();
                              }
                          
                              let table = memoryLocationsWindow.invalidate().tables.first;
                              if (!table.exists) throw 'Could not find memory locations table';
                          
                              const columns = memoryLocationsWindow.table.childrenByRole("AXColumn")
                                  .map(col => col.title.invalidate().value.trim());
                          
                              const numberColumnIndex = columns.indexOf("Numeration");
                              const nameColumnIndex = columns.indexOf("Name");
                          
                              let items = table.childrenByRole("AXRow").map(item => {
                                  let getCellValue = (columnIndex) => item.children[columnIndex].children[0].title.value;
                          
                                  return {
                                      num: getCellValue(numberColumnIndex),
                                      text: getCellValue(nameColumnIndex),
                                  }
                              });
                          
                              return items;
                          }
                          
                          function selectBetweenMemoryLocationsByName({ name1, name2 }) {
                              let locations = getMemoryLocations();
                          
                              let location1 = locations.find(l => l.text === name1);
                              let location2 = locations.find(l => l.text === name2);
                          
                              if (!location1) throw `Could not find a memory location by name '${name1}'`;
                              if (!location2) throw `Could not find a memory location by name '${name2}'`;
                          
                              let locNum1 = Number(location1.num.trim());
                              let locNum2 = Number(location2.num.trim());
                          
                              sf.ui.proTools.memoryLocationsGoto({
                                  memoryLocationNumber: locNum1,
                                  useKeyboard: true,
                              });
                              sf.ui.proTools.memoryLocationsGoto({
                                  memoryLocationNumber: locNum2,
                                  extendSelection: true,
                                  useKeyboard: true,
                              });
                          }
                          
                          selectBetweenMemoryLocationsByName({
                              name1: 'START',
                              name2: 'END',
                          });
                          

                          Take it for a spin :-)

                          1. TTristan Hoogland @Tristan
                              2022-12-09 16:43:26.808Z

                              Thanks Kitch! Didn't have any luck recreating the earlier one, but if it appears again I'll try keep a track of why it's happening. In the meantime I'll give this a test drive and report back!

                              1. TTristan Hoogland @Tristan
                                  2022-12-10 23:10:58.085Z

                                  Hey Kitch - so far i think it's working great! Again haven't been able to accurately reproduce the issue from before so who knows. Stay tuned anyway.

                                  I had another question though that I did run into (not sure if it's entirely related, but kind of). Do you have any tips on clearing the existing selection? I've noticed if there's an existing selection of sorts it will have trouble selecting between the two markers and seem to try hold on to the existing selection. Even if I deselect all tracks the selection stays the same up in the playhead.

                                  I had one solution that nearly worked, which was to effectively while (true) move edit selection left (from the PT menu), but it seems once the script starts off the move edit selection left options seem to stay true until you run the script all over again.

                                  The only version that works which is kind of a faux-while true is this, but I think doesn't seem particularly ideal:

                                  let moveEditLeftEnabled = sf.ui.proTools.getMenuItem("Edit", "Selection", "Move Edit Left");
                                  
                                  function moveEditSelectionLeft() {
                                  //set arbitrary number to max out at
                                      for (let i = 0; i < 200; i++) {
                                          if (moveEditLeftEnabled.isEnabled === true) {
                                              sf.ui.proTools.menuClick({ menuPath: ["Edit", "Selection", "Move Edit Left"] });
                                          }
                                      }
                                  }
                                  moveEditSelectionLeft();
                                  

                                  I can work it out with keyboard strikes, but I'm trying to avoid those at all costs for obvious reasons :)

                                  Edit: It's probably assumed, but I'm placing this before calling the select between markers function

                                  1. Kitch Membery @Kitch2022-12-10 23:18:10.501Z

                                    Have you tried setting the selection length to 0 samples?

                                    sf.ui.proTools.appActivateMainWindow();
                                    
                                    sf.ui.proTools.selectionSetInSamples({
                                        selectionLength: 0
                                    });
                                    
                                    1. TTristan Hoogland @Tristan
                                        2022-12-10 23:22:49.654Z2022-12-10 23:28:57.466Z

                                        Don't load the question (you know I haven't) - I didn't know that!

                                        Thanks.

                                        Is going back to the top of the timeline best done using a menuClick on "return to zero"?

                                        Just nvm - Kitch, i got it all! Sorry for the false starts on these rudimentary ones. Must be that cold/flu I've got!

                                        1. Kitch Membery @Kitch2022-12-10 23:29:56.740Z

                                          Hmmm...
                                          You mean an elementClick() on "return to zero"? If so yep!

                                          sf.ui.proTools.mainWindow.transportViewCluster.transportButtons.returnToZeroButton.elementClick()
                                          
                                          1. TTristan Hoogland @Tristan
                                              2022-12-10 23:30:22.609Z

                                              yep sorry that's what i meant eurgh i'm definitely too hazy today <3

                                            • In reply toTristan:
                                              Kitch Membery @Kitch2022-12-10 23:30:27.866Z

                                              I loaded the question again... Ha!

                                      • In reply toKitch:
                                        Eric Huergo @Eric_Huergo
                                          2023-02-01 17:33:56.253Z

                                          Hey @Kitch, hope you've been well sir!!! Was just wondering - this script works a treat but is there any way to make the memory locations it chooses from (START/END) case-insensitive?

                                          I was looking at some of @chrscheuer 's recs for different script an saw the following:

                                          var trackNames = sf.ui.proTools.trackNames.filter(n => n.match(/(Guitar|Gtr|Gt)/i));
                                          
                                          sf.ui.proTools.trackSelectByName({
                                              names: trackNames,
                                              deselectOthers: true,
                                          });
                                          

                                          ------ *code snippet from Select Track Names using keywords by @chrscheuer *

                                          However, when I try and implement it gets all funky on me which makes me guess my syntax is off somehow (still working on my regex). Any suggestions on incorporating these two ideas?

                                          1. Kitch Membery @Kitch2023-02-01 18:52:09.056Z

                                            Hi @Eric_Huergo,

                                            Which script are you working from (as there are a bunch of different scripts in this thread.)? Let me know and I'll take a look. :-)

                                            1. Eric Huergo @Eric_Huergo
                                                2023-02-01 19:31:18.324Z

                                                Working precisely off of this version of your code! :)

                                                function getMemoryLocations() {
                                                    sf.ui.proTools.appActivateMainWindow();
                                                
                                                    let memoryLocationsWindow = sf.ui.proTools.memoryLocationsWindow;
                                                
                                                    if (!memoryLocationsWindow.invalidate().exists) {
                                                        sf.ui.proTools.getMenuItem('Window', 'Memory Locations')
                                                            .elementClick({}, 'Could not click to open Memory Locations window');
                                                
                                                        sf.ui.proTools.memoryLocationsWindow.elementWaitFor();
                                                    }
                                                
                                                    let table = memoryLocationsWindow.invalidate().tables.first;
                                                    if (!table.exists) throw 'Could not find memory locations table';
                                                
                                                    const columns = memoryLocationsWindow.table.childrenByRole("AXColumn")
                                                        .map(col => col.title.invalidate().value.trim());
                                                
                                                    const numberColumnIndex = columns.indexOf("Numeration");
                                                    const nameColumnIndex = columns.indexOf("Name");
                                                
                                                    let items = table.childrenByRole("AXRow").map(item => {
                                                        let getCellValue = (columnIndex) => item.children[columnIndex].children[0].title.value;
                                                
                                                        return {
                                                            num: getCellValue(numberColumnIndex),
                                                            text: getCellValue(nameColumnIndex),
                                                        }
                                                    });
                                                
                                                    return items;
                                                }
                                                
                                                function selectBetweenMemoryLocationsByName({ name1, name2 }) {
                                                    let locations = getMemoryLocations();
                                                
                                                    let location1 = locations.find(l => l.text === name1);
                                                    let location2 = locations.find(l => l.text === name2);
                                                
                                                    if (!location1) throw `Could not find a memory location by name '${name1}'`;
                                                    if (!location2) throw `Could not find a memory location by name '${name2}'`;
                                                
                                                    let locNum1 = Number(location1.num.trim());
                                                    let locNum2 = Number(location2.num.trim());
                                                
                                                    sf.ui.proTools.memoryLocationsGoto({
                                                        memoryLocationNumber: locNum1,
                                                        useKeyboard: true,
                                                    });
                                                    sf.ui.proTools.memoryLocationsGoto({
                                                        memoryLocationNumber: locNum2,
                                                        extendSelection: true,
                                                        useKeyboard: true,
                                                    });
                                                }
                                                
                                                selectBetweenMemoryLocationsByName({
                                                    name1: 'START',
                                                    name2: 'END',
                                                });
                                                
                                                1. Kitch Membery @Kitch2023-02-01 21:25:39.186Z

                                                  Hi @Eric_Huergo,

                                                  I've made a few changes, but this should do the trick :-)

                                                  function getMemoryLocations() {
                                                      sf.ui.proTools.appActivateMainWindow();
                                                  
                                                      let memoryLocationsWindow = sf.ui.proTools.memoryLocationsWindow;
                                                  
                                                      let table = memoryLocationsWindow.invalidate().tables.first;
                                                      if (!table.exists) throw 'Could not find memory locations table';
                                                  
                                                      const columns = memoryLocationsWindow.table.childrenByRole("AXColumn")
                                                          .map(col => col.title.invalidate().value.trim());
                                                  
                                                      const numberColumnIndex = columns.indexOf("Numeration");
                                                      const nameColumnIndex = columns.indexOf("Name");
                                                  
                                                      let items = table.childrenByRole("AXRow").map(item => {
                                                          let getCellValue = (columnIndex) => item.children[columnIndex].children[0].title.value;
                                                  
                                                          return {
                                                              num: getCellValue(numberColumnIndex),
                                                              text: getCellValue(nameColumnIndex),
                                                          }
                                                      });
                                                  
                                                      return items;
                                                  }
                                                  
                                                  function selectBetweenMemoryLocationsByName({ name1, name2 }) {
                                                      sf.ui.proTools.appActivateMainWindow();
                                                  
                                                      sf.ui.proTools.memoryLocationsEnsureWindow({
                                                          action: () => {
                                                              let locations = getMemoryLocations();
                                                  
                                                              log(locations);
                                                  
                                                              let location1 = locations.find(l => l.text.toLowerCase() === name1.toLowerCase());
                                                              let location2 = locations.find(l => l.text.toLowerCase() === name2.toLowerCase());
                                                  
                                                              if (!location1) throw `Could not find a memory location by name '${name1}'`;
                                                              if (!location2) throw `Could not find a memory location by name '${name2}'`;
                                                  
                                                              let locNum1 = Number(location1.num.trim());
                                                              let locNum2 = Number(location2.num.trim());
                                                  
                                                              sf.ui.proTools.memoryLocationsGoto({
                                                                  memoryLocationNumber: locNum1,
                                                                  useKeyboard: true,
                                                              });
                                                              sf.ui.proTools.memoryLocationsGoto({
                                                                  memoryLocationNumber: locNum2,
                                                                  extendSelection: true,
                                                                  useKeyboard: true,
                                                              });
                                                          }, restoreWindowOpenState: true
                                                      });
                                                  }
                                                  
                                                  selectBetweenMemoryLocationsByName({
                                                      name1: 'START',
                                                      name2: 'END',
                                                  });
                                                  

                                                  I used the toLowercase() method for the following 2 lines to make them match with case insensitivity.
                                                  ``
                                                  let location1 = locations.find(l => l.text.toLowerCase() === name1.toLowerCase());
                                                  let location2 = locations.find(l => l.text.toLowerCase() === name2.toLowerCase());

                                                  
                                                  Note: Something to be aware of... I believe you can have more than one memory location with the same name... This script will find the first of each.
                                                  1. Eric Huergo @Eric_Huergo
                                                      2023-02-01 21:54:29.342Z

                                                      Absolutely incredible, thank you much dude!!! Also, the disclaimer on the inner workings of the function is greatly appreciated. Thanks for your awesome work, this is definitely working now and super useful to know how to handle case! Thank you!!!!! :)

                                                      1. Kitch Membery @Kitch2023-02-02 00:52:49.882Z

                                                        You're welcome @Eric_Huergo :-)

                                                        1. AAdam Lilienfeldt @Adam_Lilienfeldt
                                                            2025-01-10 09:48:02.281Z

                                                            Hi Kitch!

                                                            It seems as if the memory locations in PT works a it differently as of a recent update.
                                                            I'm getting this error using the script:

                                                            Error in EnsureMemoryLocationsWindowAction: Could not find a memory location by name 'START'
                                                            (Select between mem locations line 39)  (Select between mem locations: Line 30)
                                                            

                                                            Is there a workaround in getting it to work with the new PT-update? Getting this script up and running would be amazing!

                                                            1. TTristan Hoogland @Tristan
                                                                2025-01-10 21:34:47.195Z

                                                                This is a lot more easily achieved with the newer SDK. Something like this should work.

                                                                function selectBetweenMarkers(marker1, marker2) {
                                                                
                                                                    const memoryLocations = sf.app.proTools.memoryLocations.invalidate().allItems;
                                                                
                                                                    const location1 = memoryLocations.find(loc => loc.name === marker1);
                                                                    const location2 = memoryLocations.find(loc => loc.name === marker2);
                                                                
                                                                    if (!location1 || !location2) {
                                                                        throw Error(`Could not find markers: ${!location1 ? marker1 : ''} ${!location2 ? marker2 : ''}`);
                                                                    }
                                                                
                                                                    sf.ui.proTools.memoryLocationsGoto({
                                                                        memoryLocationNumber: location1.number,
                                                                    });
                                                                
                                                                    sf.ui.proTools.memoryLocationsGoto({
                                                                        memoryLocationNumber: location2.number,
                                                                        extendSelection: true,
                                                                        useKeyboard: true,
                                                                    });
                                                                }
                                                                
                                                                selectBetweenMarkers('START', 'OUT');
                                                                
                                                                1. AAdam Lilienfeldt @Adam_Lilienfeldt
                                                                    2025-01-11 16:50:07.335Z

                                                                    Works like a charm. Thank you Tristan!

                                                2. In reply tochrscheuer:
                                                  LLlion Robertson @Llion_Robertson
                                                    2023-09-06 15:57:35.739Z

                                                    Genius! Thank you!

                                                  • D
                                                    In reply tomikewax:
                                                    danielkassulke @danielkassulke
                                                      2022-12-19 08:23:01.725Z

                                                      @Tristan_Hoogland is there a reason why you're using marker locations rather than a marker selection for this? That way you could navigate to a marker selection named e.g. Mix Bounce that'll never be in conflict with other markers or when they're created.

                                                      1. TTristan Hoogland @Tristan
                                                          2022-12-19 17:26:12.666Z

                                                          When it's just been me using my script in a very specific template it's rarely an issue (and using marker selection would also work), but when I've had a few friends test the script out on their system the marker system falls apart because A) not everyone uses markers the way I do B) not everyone labels them the same or sets them up at the same time and thus the numbers change.

                                                          After cracking the code with making a manual selection and leaning more on the start/end/length counters I think I may abandon markers altogether for making selections as this hasn't failed once since implementing. Though fortunately I've set this up in a way that allows for both.

                                                          In the interest of sharing here is what I'm talking about:

                                                          sf.ui.proTools.appActivateMainWindow();
                                                          
                                                          const editSelectionStart = sf.ui.proTools.mainWindow.counterDisplay.textFields.whoseTitle.is("Edit Selection Start").first;
                                                          const editSelectionEnd = sf.ui.proTools.mainWindow.counterDisplay.textFields.whoseTitle.is("Edit Selection End").first;
                                                          const editSelectionLength = sf.ui.proTools.mainWindow.counterDisplay.textFields.whoseTitle.is("Edit Selection Length").first;
                                                          
                                                          let selectionStartStr;
                                                          let selectionEndStr;
                                                          let selectionLengthStr;
                                                          
                                                          let selectionStartNumberValue;
                                                          let selectionEndNumberValue;
                                                          let selectionLengthNumberValue;
                                                          
                                                          ////////////////////////////////////////////////////////////////////////////////////////////
                                                          ////////////////////////////////////////////////////////////////////////////////////////////
                                                          /////////////////////////////////////MEMPORY LOCATIONS//////////////////////////////////////
                                                          ////////////////////////////////////GET PRINT SELECTION/////////////////////////////////////
                                                          ////////////////////////////////////////////////////////////////////////////////////////////
                                                          ////////////////////////////////////////////////////////////////////////////////////////////
                                                          
                                                          function bounceSelection() {
                                                              //current counter mode
                                                              function getMainCounterMode() {
                                                                  const mainCounterValue = sf.ui.proTools.mainWindow.counterDisplay.mainCounter.value.invalidate().value;
                                                          
                                                                  let counterMode;
                                                          
                                                                  switch (true) {
                                                                      case mainCounterValue.includes("|"):
                                                                          counterMode = "Bars|Beats"
                                                                          break;
                                                                      case mainCounterValue.includes(":") && mainCounterValue.includes("."):
                                                                          counterMode = "Min:Secs"
                                                                          break;
                                                                      case mainCounterValue.split(":").length >= 3:
                                                                          counterMode = "Timecode"
                                                                          break;
                                                                      case mainCounterValue.includes("+"):
                                                                          counterMode = "Feet+Frames"
                                                                          break;
                                                                      default:
                                                                          counterMode = "Samples"
                                                                          break;
                                                                  }
                                                          
                                                                  return counterMode
                                                              }
                                                          
                                                              const originalCounterState = getMainCounterMode()
                                                          
                                                              function setMainCounterToSamples() {
                                                                  sf.ui.proTools.mainCounterSetValue({ targetValue: "Samples" })
                                                              }
                                                          
                                                              function resetMainCounterToOriginalState() {
                                                                  sf.ui.proTools.mainCounterSetValue({ targetValue: originalCounterState })
                                                              }
                                                          
                                                              function userRangeBounceSelection() {
                                                          
                                                                  //reset/empty any existing selection
                                                                  sf.ui.proTools.selectionSetInSamples({
                                                                      selectionLength: 0
                                                                  });
                                                          
                                                                  if (!sf.ui.proTools.getMenuItem('Window', 'Memory Locations').isMenuChecked)
                                                                      sf.ui.proTools.memoryLocationsShowWindow();
                                                          
                                                                  const inMarkerDlg = sf.interaction.displayDialog({
                                                                      buttons: ["Start Selected", "Use Manual Selection", "Cancel"],
                                                                      cancelButton: "Cancel",
                                                                      defaultButton: "Start Selected",
                                                                      prompt: "Select your start bounce marker." + ("\n") + ("\n") + "Alternatively, with this dialog open, make a manual selection in the timeline and press 'Use Manual Selection'",
                                                                      title: "Select Bounce Start Marker",
                                                                  }).button;
                                                                  if (inMarkerDlg === "Start Selected") {
                                                                      //toggle to samples for accurate read
                                                                      setMainCounterToSamples();
                                                          
                                                                      //get values from counter display
                                                                      selectionStartStr = editSelectionStart.value.invalidate().value;
                                                                      selectionStartNumberValue = Number(selectionStartStr);
                                                          
                                                                      //return main counter to original state
                                                                      resetMainCounterToOriginalState();
                                                          
                                                                  } else if (inMarkerDlg === "Use Manual Selection") {
                                                                      //toggle to samples for accurate read
                                                                      setMainCounterToSamples();
                                                          
                                                                      //get values from counter display
                                                                      selectionStartStr = editSelectionStart.value.invalidate().value;
                                                                      selectionStartNumberValue = Number(selectionStartStr);
                                                                      selectionEndStr = editSelectionEnd.value.invalidate().value;
                                                                      selectionEndNumberValue = Number(selectionEndStr);
                                                                      return
                                                                  }
                                                          
                                                                  const outMarkerDlg = sf.interaction.displayDialog({
                                                                      buttons: ["End Selected", "Cancel"],
                                                                      cancelButton: "Cancel",
                                                                      defaultButton: "End Selected",
                                                                      prompt: "Select your end bounce marker",
                                                                      title: "Select Bounce End Marker",
                                                                  }).button;
                                                                  if (outMarkerDlg === "End Selected") {
                                                                      //toggle to samples for accurate read
                                                                      setMainCounterToSamples();
                                                          
                                                                      //get values from counter display
                                                                      selectionEndStr = editSelectionStart.value.invalidate().value;
                                                                      selectionEndNumberValue = Number(selectionEndStr);
                                                          
                                                                      //return main counter to original state
                                                                      resetMainCounterToOriginalState();
                                                                  }
                                                              }
                                                          
                                                              function recallEditSelection() {
                                                                  sf.wait({ intervalMs: 200 });
                                                                  sf.ui.proTools.selectionSetInSamples({
                                                                      selectionStart: selectionStartNumberValue,
                                                                      selectionEnd: selectionEndNumberValue,
                                                                  });
                                                              }
                                                          
                                                              userRangeBounceSelection();
                                                          
                                                              recallEditSelection();
                                                          
                                                              const confirmBounceSelection = sf.interaction.displayDialog({
                                                                  buttons: ["Confirm", "Select Again", "Cancel"],
                                                                  cancelButton: "Cancel",
                                                                  defaultButton: "Confirm",
                                                                  prompt: "Confirm Selection?" + ("\n") + ("\n") + "Bounces will begin after this step.",
                                                                  title: "Confirmation Dialog",
                                                              }).button;
                                                          
                                                              if (confirmBounceSelection === "Confirm") {
                                                                  //
                                                              } else if (confirmBounceSelection === "Select Again") {
                                                                  //rerun the function
                                                                  bounceSelection();
                                                                  recallEditSelection();
                                                              }
                                                              //select mix bus track in session to ensure following functions operate properly
                                                              // gotoMixBusByTrackName();
                                                          
                                                              //return counter to original state
                                                              sf.ui.proTools.mainCounterSetValue({ targetValue: originalCounterState })
                                                          }
                                                          
                                                          bounceSelection();
                                                          
                                                        • C
                                                          In reply tomikewax:
                                                          Chris Testa @Chris_Testa
                                                            2024-10-24 04:30:12.086Z

                                                            Anyone know how to apply this to deleting selections and then moving on to the next selection? For example, in most of my shows I want to make sure there is no audio within the blacks between the act breaks. I usually have a "break 1" "ACT 2" "break 2" "ACT 3" etc. Ideally I'd like to make a selection of tracks and have the selection go to "break 1" then select until "ACT 2" then delete, then move on to "break 2" and make the selection from marker "break2" to marker "ACT3" and so on.... Not sure if this script is a starting place for that type of thing.