No internet connection
  1. Home
  2. How to

Use Protools Playback as Trigger

By Giuliano Sulzberger @Giuliano_Sulzberger
    2021-04-09 09:38:31.553Z

    Hello!
    I'd like to use Protools Playback as a "Trigger" to fire a Keycommand

    So it should Fire the Keycommand when Protools Playback Starts and another one when Protools Stops

    (I Want to toggle the Microphone inside Zoom to Mute for Online Mixing Sessions)

    I'm Now doing it with the Spacebar as the Trigger wich is not Ideal as i can not type then in Protools.

    Any Help would be wonderful! Thank you!
    all the best! giuli

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

    There are 11 replies. Estimated reading time: 11 minutes

    1. samuel henriques @samuel_henriques
        2021-04-09 15:32:39.115Z2021-04-15 17:46:55.592Z

        Hi @Giuliano_Sulzberger,

        This script will run in the backgroung and log "Playing" when pro tools starts playing and log "Stoped" when you stop pro tools.
        Replace the "log" lines with the code you need.

        Let me know how it goes

        
        let currentPlayState
        
        function main() {
        
            if (sf.ui.proTools.invalidate().exists) {
                if (sf.ui.proTools.mainWindow.sessionPath != null) {
        
                    const playState = sf.ui.proTools.isPlaying
        
                    if (currentPlayState != playState) {
        
                        currentPlayState = playState
        
                        if (playState) {//    If pro tools is playing
        
                            sf.keyboard.press({ keys: "ctrl+cmd+alt+shift+x", fast: true });
        
                            //log("Playing")  //  Your code here
        
        
                        } else if (!playState) {// If pro tools is stoped
        
                            sf.keyboard.press({ keys: "ctrl+cmd+alt+shift+x", fast: true });
        
                            //log("Stoped") //  Your code here
        
                        }
                    }
                }
            }
        }
        
        
        function runForever(name, action, interval, timeout) {
            var now = (new Date).valueOf();
            if (now - globalState[name] < timeout) throw 0; //Exit if we were invoked again inside the timeout
        
            globalState[name] = now;
            sf.engine.runInBackground(function () {
                try {
                    while (true) {
                        sf.engine.checkForCancellation();
        
                        action()
        
                        sf.wait({ intervalMs: interval, executionMode: 'Background' });
                    }
                } catch (e) { log("Run forever has ended!") } finally {
                    globalState[name] = null;
                }
            });
        }
        
        
        runForever("play_Stop", main, 500, 5000);
        
        
        ReplySolution
        1. Very Good! It works! Thank you Samuel!

          For everybody that is interested.
          I just put a Shortcut into Zoom that works even when Zoom is not in Focus (Its in the Zoom Settings) That will be triggered with the Code from Samuel. I find it to be very practical i used it a bunch last week.

          • I do still get a error message when i start protools and when i stop it because the Scrip is running before protools does. Im not sure if i can get a "wait" in there somehow. (I do not programm at all. total noob here)
          1. samuel henriques @samuel_henriques
              2021-04-12 09:23:00.407Z

              hello @Giuliano_Sulzberger,

              great it's working, do you get error every time you press play and stop?
              could you share the code?

              1. samuel henriques @samuel_henriques
                  2021-04-12 10:46:41.148Z

                  UPDATED ABOVE: no more error and script fail when you open and close sessions.

                  1. Super! No Error in on Starting Protools. But there is one on Closing Protools. Not so bad.

                    I tried also to take out the LogInfoBubble Thingy that comes up on the corner of the screen by deleting log("Playing")

                    I probably broke something. So here is the code that i used after that. (With your update)

                    function runForever(name, action, interval, timeout) {
                    var now = (new Date).valueOf();
                    if (now - globalState[name] < timeout) throw 0; //Exit if we were invoked again inside the timeout

                    globalState[name] = now;
                    sf.engine.runInBackground(function () {
                        try {
                            while (true) {
                                sf.engine.checkForCancellation();
                    
                                action()
                    
                                sf.wait({ intervalMs: interval, executionMode: 'Background' });
                            }
                        } finally {
                            globalState[name] = null;
                        }
                    });
                    

                    }

                    function main() {

                    if (sf.ui.proTools.mainWindow.sessionPath != null) {
                    
                        const ptIsPlaying = sf.ui.proTools.isPlaying
                    
                        if (globalState.playState != ptIsPlaying) {
                    
                            if (ptIsPlaying) {//    If pro tools is playing
                    
                    
                                 //                //  
                            sf.keyboard.press({
                                keys: "ctrl+cmd+alt+shift+x",
                                fast: true,
                            });
                    
                    
                            } else if (!ptIsPlaying) {// If pro tools is stoped
                    
                    
                            //  // 
                            sf.keyboard.press({
                                keys: "ctrl+cmd+alt+shift+x",
                                fast: true,
                            });
                    
                            }
                        }
                        globalState.playState = ptIsPlaying
                    }
                    

                    }

                    runForever("play_Stop", main, 500, 5000);

                    1. samuel henriques @samuel_henriques
                        2021-04-12 22:22:20.628Z

                        Hi @Giuliano_Sulzberger,

                        no error on my side, the code as you posted looks correct.

                        could you start the code text on the first line of the editor and let me know what is the error and error line?

                        in the mean time, here's a great video from Kitch explaining how to quote code on the forum:
                        How to quote code in the SoundFlow forum.

                        1. Ah very good. I was wondering if it was readable that way.!

                          It just tells me 14.04.2021 09:09:04.93

                          [Backend]: AXUIElementException in LoadUIElement: kAXErrorCannotComplete AXUIElementException in LoadUIElement: kAXErrorCannotComplete

                          when i close protools. I dont know what it means i cant find any of this things in the code.

                          All the best!
                          Giuli

                          function runForever(name, action, interval, timeout) {
                              var now = (new Date).valueOf();
                              if (now - globalState[name] < timeout) throw 0; //Exit if we were invoked again inside the timeout
                          
                              globalState[name] = now;
                              sf.engine.runInBackground(function () {
                                  try {
                                      while (true) {
                                          sf.engine.checkForCancellation();
                          
                                          action()
                          
                                          sf.wait({ intervalMs: interval, executionMode: 'Background' });
                                      }
                                  } finally {
                                      globalState[name] = null;
                                  }
                              });
                          }
                          
                          
                          
                          function main() {
                          
                              if (sf.ui.proTools.mainWindow.sessionPath != null) {
                          
                                  const ptIsPlaying = sf.ui.proTools.isPlaying
                          
                                  if (globalState.playState != ptIsPlaying) {
                          
                                      if (ptIsPlaying) {//    If pro tools is playing
                          
                          
                                           //                //  
                                      sf.keyboard.press({
                                          keys: "ctrl+cmd+alt+shift+x",
                                          fast: true,
                                      });
                          
                          
                                      } else if (!ptIsPlaying) {// If pro tools is stoped
                          
                          
                                      //  // 
                                      sf.keyboard.press({
                                          keys: "ctrl+cmd+alt+shift+x",
                                          fast: true,
                                      });
                          
                                      }
                                  }
                                  globalState.playState = ptIsPlaying
                              }
                          }
                          
                          
                          
                          runForever("play_Stop", main, 500, 5000);
                          
                          
                          1. samuel henriques @samuel_henriques
                              2021-04-14 12:06:08.917Z

                              can't figure this out, could I ask you to report on Help/Issue just after getting the error, so @Kitch or @chrscheuer can have a better view of what's happening there?

                              1. samuel henriques @samuel_henriques
                                  2021-04-15 17:45:39.831Z

                                  Hello @Giuliano_Sulzberger ,

                                  I think I got it, and made a slight improvement to the script.
                                  It's updated above.

                                  Let me know how it goes

                    2. M
                      Michael Hartung @Michael_Hartung
                        2023-03-02 21:41:29.188Z

                        I really want to get this to work, but I don't understand what it means to "Replace the "log" lines with the code you need." What code do I need other than this script? I basically want what the original poster wanted, every time I press play on protools, it mutes the Zoom app microphone, and when I stop, it unmutes it. Is this script missing something to make that work? I've honestly read all the posts, but couldn't make sense of it. Looking for some help.
                        Thanks!!

                        1. G
                          Graham Archer @Graham_Archer
                            2024-04-12 14:33:42.231Z

                            @samuel_henriques this is so good!
                            Has anyone amended this code so that it works with Logic Pro X do you know?
                            It would be really useful as well.

                            Thanks so much