No internet connection
  1. Home
  2. How to

Wait for Pro Tools to start Responding

By Pinewood Studios @Pinewood_Studios
    2025-02-25 14:31:48.315Z

    Hello everyone.

    I have a script which renames multiple files on disk. It's fairly simple, just clicking 'OK' until the rename window goes away (with a few extra steps).

    The issue I have, is that on our particular macOS version/SMB storage server Pro Tools takes a really long time to rename files on disk, especially with long multi-channel files. This causes Pro Tools to hang (spinning wheel) for up to a minute between rename operations.

    Irritatingly, when Pro Tools stops responding none of my waitFor methods work properly.

    For example to take just some of the code:

    const renameWindow = sf.ui.proTools.window.whoseTitle.is("Name").first;
    const textField = renameWindow.groups.whoseTitle.is("Name".first.textFields.first;
    const okButton = renameWindow.buttons.whoseTitle.is("OK").first;
    const currentFile = textField.value.invalidate().value;
    
    okButton.elementClick();
    
    sf.waitFor({
        callback: () => (!textField.exists) || (textField.invalidate().value.value !== currentFile),
        timeout: 30000,
        onError: "ThrowError",
    })
    
    

    This works perfectly as long as Pro Tools doesn't go unresponsive, but breaks completely if it does.

    Is there an 'official' way to wait until Pro Tools starts responding again?

    Thanks.

    Fergus

    Solved in post #8, click to view
    • 8 replies
    1. I would try setting the timeout to -1 which will cause waitFor to wait indefinitely.

      sf.waitFor({
          callback: () => (!textField.exists) || (textField.invalidate().value.value !== currentFile),
          timeout: -1,
          onError: "ThrowError",
      })
      

      But I'm sure @Kitch might have a better solution.

      1. Pinewood Studios @Pinewood_Studios
          2025-02-25 17:38:52.683Z

          Hey Chris,

          I think the issue here is that the callback actually exits early, rather than erroring out. Possibly the non-responsive Pro Tools makes the textField.exists come back false?

          So this bit wouldn't be solved by an infinite timeout.

          Thanks!

          Fergus

          1. Kitch Membery @Kitch2025-02-25 18:03:44.023Z

            Hi @Pinewood_Studios (AKA Fergus)

            The first step to troubleshooting this would be to find a foolproof way to make Pro Tools unresponsive.

            This may have been covered in the forum quite some time ago, but I might be wrong.

            Let me know if you can find a way, and we can investigate if there is a robust way to wait before proceeding. :-)

            1. Pinewood Studios @Pinewood_Studios
                2025-02-26 17:57:37.499Z

                Hi Kitch,

                I have a foolproof way to recreate this on our server, but it won't be recreateable on your end. I have combed the forum but struggling to find anything...

                I can keep trying to look for ways, or we could jump on a call at some point and I can demo?

                Fergus

                1. Kitch Membery @Kitch2025-02-26 18:01:07.012Z

                  Hi @Pinewood_Studios (AKA Fergus)

                  I'll take a look and see if I can find info on this, failing that we can jump on a call sometime next week to see if we can work out a way. :-)

                  1. Pinewood Studios @Pinewood_Studios
                      2025-02-27 17:12:11.961Z

                      Hey Kitch.

                      You can force Pro Tools to stop responding by finding it's process ID (ps aux | grep "Pro Tools") and then running kill -STOP [process ID].

                      Following finding this, I think I've worked out a great way to do what I'm looking for. Posting it below.

                      sf.waitFor({
                          callback: () => {
                              try{
                                  sf.ui.proTools.appActivateMainWindow();
                                  return true;
                              } catch(err) {
                                  return false;
                              }
                          },
                          timeout: 30000,
                          onError: "ThrowError"
                      });
                      

                      If you try to activate the main window when Pro Tools is not responding it throws an error. By catching this error we can wait for Pro Tools to start responding again.

                      Would love to know your thoughts on this?

                      Fergus

                      1. Kitch Membery @Kitch2025-02-27 19:22:52.336Z

                        Hi @Pinewood_Studios (Fergus)

                        Great sleuthing!

                        Using sf.ui.proTools.appActivateMainWindow();, in this instance, would not be my preferred method here as it performs more than one task under the hood.

                        • To get the process ID, I instead used pgrep -x "Pro Tools". This will return the process number only.

                        • To pause the process ID, I used kill -STOP [process ID]

                        • To resume the process ID, I used kill -CONT [process ID]

                        • For the waitFor method, I used hasLiveValidUI property.

                        When pausing and resuming the process ID in the terminal, the following code seems to work for me.

                        sf.waitFor({
                            callback: () => sf.ui.proTools.children.first.invalidate().hasLiveValidUI,
                            pollingInterval: 500,
                            timeout: -1, // Add a timeout here or "-1" for infinite wait.
                        });
                        
                        

                        Let me know if it works for you. :-)

                        Reply3 LikesSolution
                        1. Pinewood Studios @Pinewood_Studios
                            2025-02-28 09:57:20.248Z

                            Definitely a neater way of doing it - I like the polling interval change too, I didn't realise that was a thing.

                            Cheers!