No internet connection
  1. Home
  2. How to

Insert Plugin in first available empty slot

By Fokke van Saane @Fokke
    2019-06-10 14:51:12.359Z

    Like the title say.
    Now i have to say which slot i want to occupy. that means i have to have a button for every slot.
    I'd love a macro that just inserts a PI from the list in the first available empty slot.

    Solved in post #3, click to view
    • 39 replies

    There are 39 replies. Estimated reading time: 20 minutes

    1. Hi @Fokke

      This script will insert a plugin (and ask you which one) for the first available insert slot:

      
      function getFirstFreeInsertIndex() {
          var btns = sf.ui.proTools.selectedTrack.invalidate().insertButtons;
          for (var i = 0; i < 10; i++)
              if (btns[i].value.invalidate().value === "unassigned") return i;
          return -1;
      }
      
      sf.ui.proTools.selectedTrack.trackInsertOrSendSearch({
          insertOrSend: 'Insert',
          pluginNumber: getFirstFreeInsertIndex() + 1,    
      });
      
      1. If you want to add a specific plugin, use this script:

        
        function getFirstFreeInsertIndex() {
            var btns = sf.ui.proTools.selectedTrack.invalidate().insertButtons;
            for (var i = 0; i < 10; i++)
                if (btns[i].value.invalidate().value === "unassigned") return i;
            return -1;
        }
        
        sf.ui.proTools.selectedTrack.trackInsertOrSendSelect({
            insertOrSend: 'Insert',
            pluginNumber: getFirstFreeInsertIndex() + 1,    
            pluginPath: ['plug-in', 'EQ', 'EQ3 7-Band (mono)']
        });
        
        Reply2 LikesSolution
        1. GGraham Archer @Graham_Archer
            2019-10-21 14:35:51.806Z

            Hey @chrscheuer how do you do this for multiple tracks? As I want to put the same plugin across multiple tracks - I tried adding:

            sf.keyboard.modifiers({ isShift: true isOption: true, });

            But it didn't seem to have any effect. Any help would be much appreciated!

            1. Hi @Graham_Archer

              Add selectForAllSelectedTracks: true to the last action:

              function getFirstFreeInsertIndex() {
                  var btns = sf.ui.proTools.selectedTrack.invalidate().insertButtons;
                  for (var i = 0; i < 10; i++)
                      if (btns[i].value.invalidate().value === "unassigned") return i;
                  return -1;
              }
              
              sf.ui.proTools.selectedTrack.trackInsertOrSendSelect({
                  insertOrSend: 'Insert',
                  pluginNumber: getFirstFreeInsertIndex() + 1,    
                  pluginPath: ['plug-in', 'EQ', 'EQ3 7-Band (mono)'],
                  selectForAllSelectedTracks: true,
              });
              

              Note this will only check the 1st selected track for the next available insert, so any further selected tracks with inserts on that particular slot will be overridden.

              1. GGraham Archer @Graham_Archer
                  2019-10-21 15:08:26.713Z

                  Brilliant! Thanks so much @chrscheuer - works perfectly. So useful.

                  1. GGraham Archer @Graham_Archer
                      2019-10-22 14:14:21.296Z

                      Hey @chrscheuer,

                      I just wanted to know if this is possible - basically I want to cycle through each plugin, opening the plugin window, wait, press a shortcut, close the plugin window and then move on to the next plugin on the next selected track. I'm guessing this will be in a for loop for the number of selected tracks, something like:

                      sf.ui.proTools.selectedTrack.trackInsertToggleShow(); sf.wait({ intervalMs: 2000, }); sf.keyboard.press({ keys: 'shift+ctrl+alt+cmd+t' }); sf.ui.proTools.selectedTrack.trackInsertToggleShow();

                      Also inserting the plugins seems to be dependant on track height - as in if the track height is 'mini' or 'micro' the plugin won't get inserted, but small or bigger seems fine. Is that intentional?

                      As ever, thanks in advance!

                      1. What does the shortcut do?

                        1. GGraham Archer @Graham_Archer
                            2019-10-22 14:18:48.214Z

                            It's for Melodyne - I've got it set to hit the 'Transfer' button but that's a custom allocation that I've made.

                  2. In reply tochrscheuer:
                    Mike Wax @mikewax
                      2020-06-22 20:37:13.563Z

                      Hello, I was wondering if this was possible to do on a specific track? For example, if i have Track A, Track B, Track C, Track D, can i have it insert the plugin on Track B?

                      1. Hi Mike.

                        Right now the script uses sf.ui.proTools.selectedTrack in a few places.
                        You could use a call to sf.ui.proTools.trackGetByName( ... ) to make it happen on a specific track.

                        1. Mike Wax @mikewax
                            2020-06-22 20:58:00.674Z

                            It's throwing an error about invalidate()

                            This is what i have:

                            `function getFirstFreeInsertIndex() {
                            var btns = sf.ui.proTools.trackGetByName('RX').invalidate().insertButtons;
                            for (var i = 0; i < 10; i++)
                            if (btns[i].value.invalidate().value === "unassigned") return i;
                            return -1;
                            }

                            sf.ui.proTools.selectedTrack.trackInsertOrSendSelect({
                            insertOrSend: 'Insert',
                            pluginNumber: getFirstFreeInsertIndex() + 1,
                            pluginPath: ['multichannel plug-in', 'Noise Reduction', 'RX 7 Monitor (stereo)']
                            });`

                            1. Hi Mike.

                              Try this instead:

                              
                              const track = sf.ui.proTools.trackGetByName({ name: 'RX' }).track;
                              
                              function getFirstFreeInsertIndex() {
                                  var btns = track.insertButtons;
                                  for (var i = 0; i < 10; i++)
                                      if (btns[i].value.invalidate().value === "unassigned") return i;
                                  return -1;
                              }
                              
                              track.trackInsertOrSendSelect({
                                  insertOrSend: 'Insert',
                                  pluginNumber: getFirstFreeInsertIndex() + 1,
                                  pluginPath: ['multichannel plug-in', 'Noise Reduction', 'RX 7 Monitor (stereo)']
                              });
                              
                              
                              1. Mike Wax @mikewax
                                  2020-06-22 21:03:05.372Z

                                  It seems to still be throwing an error:

                                  Error: Parent's UIElement was null: SoundFlow.Shortcuts.AXUIElementException: kAXErrorInvalidUIElement at SoundFlow.Shortcuts.AXUIElement.GetSubElements(String) + 0x1a4 at SoundFlow.Shortcuts.Ax.AxNodes.AxPtTrackInsertSendButton.GetUIElement() + 0xe6 at SoundFlow.Shortcuts.Ax.AxNodes.AxElement.LoadUIElement() + 0x2a (AxPtTrackInsertSendButton) (Add RX Monitor line 31)

                                  1. Are you having all insert buttons showing, and is the track RX visible?

                        2. In reply tochrscheuer:
                          NNacho @Nacho_Sotelo
                            2020-04-06 22:44:02.247Z2020-04-06 23:04:38.123Z

                            Is there a way to do this but instead of using the SoundFlow search menu, use the Pro Tools search?

                            Something like select the first free insert and activate search menu item

                            1. Brilliant idea :)

                              Yes - here's how to do that:

                              function getFirstFreeInsertIndex() {
                                  var btns = sf.ui.proTools.selectedTrack.invalidate().insertButtons;
                                  for (var i = 0; i < 10; i++)
                                      if (btns[i].value.invalidate().value === "unassigned") return i;
                                  throw 0;
                              }
                              
                              sf.ui.proTools.selectedTrack.insertButtons[getFirstFreeInsertIndex()].popupMenuSelect({
                                  menuPath: ['search...']
                              });
                              
                              1. NNacho @Nacho_Sotelo
                                  2020-04-07 16:49:54.820Z

                                  Works great here, thank you!

                                  1. In reply tochrscheuer:
                                    RRobert Sörling @robertsorling
                                      2020-09-13 08:21:58.821Z

                                      Hi! Is there a way to do this for a given insert slot? For example ”open protools own search field for insert number 3 on selected track”?

                                      1. Yes, you just put in the insert index (one less than the insert number) - so to do this for the 3rd I put in 2 here:

                                        sf.ui.proTools.selectedTrack.insertButtons[2].popupMenuSelect({
                                            menuPath: ['search...']
                                        });
                                        
                                      2. In reply tochrscheuer:
                                        JJoe Kearns @Joe_Kearns
                                          2021-09-06 18:16:37.682Z

                                          this is so good.

                                          is there a way to make it automatically type in a specific plugin and press enter after it gets to the PT search menu please?

                                          1. Hi Joe,

                                            Have you checked out the Teezio Plugin Loader? It does all this fully automatically for you :)

                                    • G
                                      In reply toFokke:
                                      Graham Archer @Graham_Archer
                                        2019-12-12 09:38:30.559Z2021-09-06 21:16:17.298Z

                                        Hey @chrscheuer apologies I had this working and now it seems to be not working and I'm not quite sure why! Here's the code I'm using:

                                        //Only works on tracks with vertical height of small or larger
                                        //Get first free insert
                                        function getFirstFreeInsertIndex() {
                                            var btns = sf.ui.proTools.selectedTrack.invalidate().insertButtons;
                                            for (var i = 0; i < 10; i++)
                                                if (btns[i].value.invalidate().value === "unassigned") return i;
                                            return -1;
                                        }
                                        var numberOfTracks = sf.ui.proTools.selectedTrackCount;
                                        //Insert Melodyne
                                        sf.ui.proTools.selectedTrack.trackInsertOrSendSelect({
                                            insertOrSend: 'Insert',
                                            pluginNumber: getFirstFreeInsertIndex() + 1,    
                                            pluginPath: ['plug-in', 'Other', 'Melodyne (mono)'],
                                            //pluginPath: ['plug-in', 'Dynamics', 'BF-2A (mono)'],
                                            selectForAllSelectedTracks: true,
                                        });
                                        

                                        The script is flagging an error saying

                                        Error in line 11:
                                        Could not select plugin menu item: 'plug-in', 'Other', 'Melodyne (mono)'

                                        Do you need to specify whether the plugin is DSP or Native as well? That's just a guess on my part but I've tried a few things and can't get it to work. Any help would be much appreciated!

                                        Thanks!

                                        Graham

                                        1. G
                                          In reply toFokke:
                                          Graham Archer @Graham_Archer
                                            2020-01-08 17:12:29.346Z

                                            Hey @chrscheuer

                                            I had this working great but now I can't even get this simpler code to insert a plugin:

                                            sf.ui.proTools.selectedTrack.trackInsertOrSendSelect({ insertOrSend: 'Insert', pluginNumber: 1, pluginPath: ['plug-in', 'Other', 'Melodyne (mono)'] });

                                            Does the pluginPath need to be 'mono plug-in'? Or has something changed to trackInsertOrSendSelect? Or is there something glaringly obvious that I'm not seeing?

                                            Please let me know when you can.

                                            Many thanks!

                                            1. Hi Graham.

                                              The path needs to be exactly identical to how it looks in the UI. So if the menu's name is mono plug-in then yes that's what your script should say.
                                              Without a screenshot of the actual menu you're trying to script it's hard to tell you what the script should look like.

                                            2. G
                                              In reply toFokke:
                                              Graham Archer @Graham_Archer
                                                2020-01-08 17:33:19.125Z

                                                Hey!

                                                OK sure thing - I've attached a screenshot so you can see.

                                                Apologies I'm a bit stumped as to why it did work and now it's not.

                                                Any help would be much appreciated.

                                                Thank you!

                                                1. Hi Graham.

                                                  Mark these words I said before:

                                                  The path needs to be exactly identical to how it looks in the UI.

                                                  With emphasis on exactly identical

                                                  Your screenshot clearly shows the first level menu item is called "Native plug-in" while your script just says "plug-in":

                                                  sf.ui.proTools.selectedTrack.trackInsertOrSendSelect({
                                                      insertOrSend: 'Insert',
                                                      pluginNumber: 1,
                                                      pluginPath: ['plug-in', 'Other', 'Melodyne (mono)']
                                                  });
                                                  

                                                  The reason why this worked before and doesn't work now is that Pro Tools in the current context (your current session on the current track) displays a different menu (it used to be named "plug-in" but is now named "Native plug-in".
                                                  The reason for that might be that on this track on this system you now have access to DSP enabled plugins, which you didn't have (due to either system, track types or other routing patterns) when this script worked before.

                                                  Unfortunately the Track Insert Or Send Select action does not accept the plugin path if it's not (and I repeat) exactly identical to the path in the menu.

                                                  1. I still wanna make sure you understand this part, but once you are on board with this, I think the question we should be asking instead should be - is there a way to choose from different menus depending on what succeeds or not.
                                                    And yes there is - several ways. But I wanna make sure you understand the concept before we make it more complex.

                                                    1. In other words, what we can deduce is that Pro Tools' first level menu items for plugins change names depending on situation.

                                                      They can be:

                                                      Mono channel, no DSP

                                                      • plug-in

                                                      Multi channel, no DSP

                                                      • multichannel plug-in
                                                      • multi-mono plug-in

                                                      Mono channel, with DSP

                                                      • DSP plug-in
                                                      • Native plug-in

                                                      Multi channel, with DSP

                                                      Actually - I'm not sure about this since I don't have DSP access here...

                                                      • DSP multichannel plug-in
                                                      • DSP multi-mono plug-in
                                                      • Native multichannel plug-in
                                                      • Native multi-mono plug-in
                                                      1. So you can see theoretically there are 9 different names for that first menu. If we didn't have the powers of SoundFlow javascripting then you'd essentially have to make 9 different commands - and that would suck.
                                                        So what we should design instead is a command that allows you to say:

                                                        • Select Melodyne on insert 1
                                                        • Choose Multichannel or multi-mono if we are potentially on a multi channel track (eg. stereo)
                                                        • Choose DSP or Native if we are potentially on a DSP enabled system and the current insert slot position allows for DSP
                                                        1. GGraham Archer @Graham_Archer
                                                            2020-01-08 23:12:34.020Z

                                                            Yes I think you're right, it would be good and more robust if the script selected Melodyne regardless of whether or not you were working on a DSP system or a non-DSP system, or if you had a mono or multichannel track selected. How can I interrogate the first level of the plugin path? With a series of 'if' statements?

                                                            1. In reply tochrscheuer:
                                                              Andrew Scheps @Andrew_Scheps
                                                                2020-02-22 12:29:25.900Z2020-02-22 12:46:50.635Z

                                                                Did you guys ever go any further on this? I'd love to see an example of the version that can deal with all the different variations of the plugin menu.

                                                                I've done a simple mono/stereo version using error handling, but to make this handle the 9 possibilities would make it quite messy. It also opens the menu each time it's checking so if you got to the ninth possibility that would be a LOT of menu flashing. Is there a way to read the text of the popup menu to determine the correct version of the command to use?

                                                                sf.ui.proTools.selectedTrack.trackInsertOrSendSelect({
                                                                    insertOrSend: "Insert",
                                                                    pluginNumber: 1,
                                                                    pluginPath: ["plug-in","EQ","EQ3 7-Band (mono)"],
                                                                }, function(notMonoTrack) {
                                                                sf.ui.proTools.selectedTrack.trackInsertOrSendSelect({
                                                                    insertOrSend: "Insert",
                                                                    pluginNumber: 1,
                                                                    pluginPath: ["multichannel plug-in","EQ","EQ3 7-Band (stereo)"],
                                                                })});
                                                                
                                                                1. I think we need an update to SoundFlow for scripts to have access to filter dynamically on the menu path. I'll log a bug report for this so we make sure to address it.

                                                                  1. Confirming we'll get a way to do this more elegantly in 3.5

                                                                    1. Chad Wahlbrink @Chad2020-03-29 14:18:52.817Z

                                                                      Hey! I was curious if this is something that has been addressed in a more recent update or if this is still being worked on?

                                                                        1. Chad Wahlbrink @Chad2020-03-29 16:38:49.160Z

                                                                          Thanks so much! This app is incredible. You are a hero.

                                                              • In reply tochrscheuer:
                                                                GGraham Archer @Graham_Archer
                                                                  2020-01-08 22:47:10.273Z

                                                                  Also I just wanted to post a screenshot of the first level menu items on a multichannel track on a DSP system in case you or anyone else needed it or found it useful for syntax.

                                                                  1. Thanks for the screenshot!

                                                              • In reply tochrscheuer:
                                                                GGraham Archer @Graham_Archer
                                                                  2020-01-08 22:42:34.605Z

                                                                  Yes you are exactly right - apologies, I must have been on a non-DSP Pro Tools system when I tested this last and it worked fine and then moved to my main setup which is DSP based. Now I understand why it didn't work, so thank you!