No internet connection
  1. Home
  2. How to

Relink

By Mark Mangini @Mark_Mangini
    2021-04-10 17:19:18.324Z

    Can anyone help me with a Macro that opens the Relink window in PT? After way too much time trying to actually find it, here's what the user must do: In an open Pro Tools session type OPTION/O (letter not number). That will open the workspace window. Do not use the keyboard shortcut to open the WORKSPACE window as it will not highlight the current open session which is the only way you can get the relink window. After typing OPTION/O, right click on the already highlighted session and a floating menu pops up with four choices. Click on Relink Offline and the desired relink window opens.

    Solved in post #5, click to view
    • 87 replies

    There are 87 replies. Estimated reading time: 39 minutes

    1. Kitch Membery @Kitch2021-04-11 19:05:06.654Z2021-04-11 19:44:23.236Z

      Hi @Mark_Mangini,

      This should do the trick. :-)

      const sessionPath = sf.ui.proTools.mainWindow.sessionPath;
      const sessionName = sessionPath.split('/').slice(-1)[0].split('.').slice(0, -1).join('.');
      
      function openWorkspace() {
          const win = sf.ui.proTools.windows.whoseTitle.startsWith("Workspace: ").first;
      
          //If a workspace window is not open, open it.
          if (!win.exists) {
              sf.keyboard.press({
                  keys: "alt+o",
              });
          }
      
          //Wait for Worksapce window
          win.elementWaitFor();
      }
      
      function openRelinkWindow() {
          let win = sf.ui.proTools.windows.whoseTitle.startsWith("Workspace: ").first;
          let textGrid = win.tables.whoseTitle.is("TextGridView").allItems[1];
          let rows = textGrid.children.whoseRole.is("AXRow");
          let sessionRow = rows.filter(e => e.children.first.children.first.title.invalidate().value === sessionName)[0];
      
          //Open right click popup menu
          let sessionRowMenu = sessionRow.childrenByRole("AXCell").first.popupMenuOpenFromElement({
              isRightClick: true,
          }).popupMenu;
      
          //Right Click on Session File Name
          sessionRowMenu.popupMenuSelect({ isRightClick: true, menuPath: ['Relink Offline'] });
      
          //Wait for window to appear
          sf.ui.proTools.windows.whoseTitle.is("Relink").first.elementWaitFor();
      }
      
      function main() {
          //Activate Pro Tools Main Window
          sf.ui.proTools.appActivateMainWindow();
      
          openWorkspace();
      
          openRelinkWindow();
      }
      
      main();
      
      1. M
        In reply toMark_Mangini:
        Mark Mangini @Mark_Mangini
          2021-04-11 19:11:24.760Z

          You are a genius! Can you add a "Hide floating windows" Command at the end of the code? In my configuration, the Workspace window stays in the foreground even thought the Relink window is the active window, thus obscuring it. Like this:

          1. MMark Mangini @Mark_Mangini
              2021-04-11 19:12:23.566Z

              Like this:

              1. Kitch Membery @Kitch2021-04-11 19:51:54.413Z

                Sure...

                This should do the trick :-)

                const sessionPath = sf.ui.proTools.mainWindow.sessionPath;
                const sessionName = sessionPath.split('/').slice(-1)[0].split('.').slice(0, -1).join('.');
                
                function openWorkspace() {
                    const win = sf.ui.proTools.windows.whoseTitle.startsWith("Workspace: ").first;
                
                    //If a workspace window is not open, open it.
                    if (!win.exists) {
                        sf.keyboard.press({
                            keys: "alt+o",
                        });
                    }
                
                    //Wait for Worksapce window
                    win.elementWaitFor();
                }
                
                function openRelinkWindow() {
                    let win = sf.ui.proTools.windows.whoseTitle.startsWith("Workspace: ").first;
                    let textGrid = win.tables.whoseTitle.is("TextGridView").allItems[1];
                    let rows = textGrid.children.whoseRole.is("AXRow");
                    let sessionRow = rows.filter(e => e.children.first.children.first.title.invalidate().value === sessionName)[0];
                
                    //Open right click popup menu
                    let sessionRowMenu = sessionRow.childrenByRole("AXCell").first.popupMenuOpenFromElement({
                        isRightClick: true,
                    }).popupMenu;
                
                    //Right Click on Session File Name
                    sessionRowMenu.popupMenuSelect({ isRightClick: true, menuPath: ['Relink Offline'] });
                
                    //Wait for relink window to appear
                    sf.ui.proTools.windows.whoseTitle.is("Relink").first.elementWaitFor();
                
                    //Close Workspace window
                    win.windowClose();
                
                    //Wait for Workspace window to disappear
                    win.elementWaitFor({waitType:'Disappear'});
                }
                
                function main() {
                    //Activate Pro Tools Main Window
                    sf.ui.proTools.appActivateMainWindow();
                
                    openWorkspace();
                
                    openRelinkWindow();
                }
                
                main();
                
                Reply1 LikeSolution
            • M
              In reply toMark_Mangini:
              Mark Mangini @Mark_Mangini
                2021-04-11 20:02:51.805Z

                Thanks Kitch. That worked great! Much appreciated.

                1. R
                  In reply toMark_Mangini:
                  rick @rick
                    2022-02-24 13:34:09.016Z

                    Hi Kitch, Do you have a script for only opening the workspace window without opening the Relink window?
                    Thanks:)

                    1. Kitch Membery @Kitch2022-02-24 19:08:51.646Z

                      Hi @rick,

                      This should do the trick.

                      function openWorkspace() {
                          const win = sf.ui.proTools.windows.whoseTitle.startsWith("Workspace: ").first;
                      
                          //If a workspace window is not open, open it.
                          if (!win.exists) {
                              sf.ui.proTools.menuClick({
                                  menuPath: ["Window", "New Workspace", "Default"],
                              });
                          }
                      
                          //Wait for Worksapce window
                          win.elementWaitFor();
                          win.elementRaise();
                      }
                      
                      openWorkspace();
                      

                      Rock on!

                      1. Rrick @rick
                          2022-02-24 22:15:28.266Z

                          Thank you Sir, very much appreciated!!

                          1. Kitch Membery @Kitch2022-02-25 00:23:41.436Z

                            You're welcome @rick :-)

                          2. In reply toKitch:
                            AAndrew Sherman @Andrew_Sherman
                              2022-04-11 09:18:35.410Z

                              Hi Kitch,

                              I've seen that you use functions like this in a few of your excellent scripts. What is the reason for it? As far as I can see one would be able to perform the command within the function without needing the function itself. However with my limited Javascript understanding I'm thinking maybe you're doing it like this as a sort of best practice so that the function could be called multiple times in a more complex script without having to spell it out each time. Is that correct?

                              1. Kitch Membery @Kitch2022-04-11 17:56:56.502Z

                                Hi @Andrew_Sherman,

                                Great question... And your assumption is correct. In the above function the the contents can be used without being inside the function.

                                It's good practice to create reusable functions. I have a library of them that I've created that I reuse all the time.

                                Here is an sudo-example of three functions being called from the "main" function.

                                function myFirstFunction(){
                                    log('This text is being logged from "myFirstFunction"')
                                }
                                
                                function mySecondFunction(){
                                    log('This text is being logged from "mySecondFunction"')
                                }
                                
                                function myThirdFunction(){
                                    log('This text is being logged from "myThirdFunction"')
                                }
                                
                                function main() {
                                
                                    myFirstFunction();
                                
                                    mySecondFunction();
                                
                                    myThirdFunction();
                                
                                    myFirstFunction();
                                }
                                
                                main();
                                

                                Rock on!

                                1. AAndrew Sherman @Andrew_Sherman
                                    2022-04-11 18:06:13.543Z

                                    Excellent, I can see that I'm going to use these a lot

                                    1. Kitch Membery @Kitch2022-04-11 18:06:55.331Z

                                      Awesome!!! :-)

                                      1. hey @Kitch, this doesn't seem to be working in the latest version of PT (2022.12) i wonder if the menu choices have changed since you wrote

                                        click to show
                            • R
                              In reply toMark_Mangini:
                              randy matuszewski @randy_matuszewski
                                2023-01-27 17:39:57.934Z

                                hey @Kitch, regretfully this appears broken again with the latest update. obviously, if you have time to patch this, it would be great but no sweat if you can't i'd hate to keep hounding you!

                                soundflow is giving an error in line 25 "could not open popup menu" thanks!

                                1. Kitch Membery @Kitch2023-01-27 19:01:41.951Z

                                  Hi @randy_matuszewski,

                                  Can you do a screen recording of the issue, that way I'll hopefully be able to see what is causing the problem. :-)

                                  1. MMark Mangini @Mark_Mangini
                                      2023-03-19 18:08:40.738Z

                                      Yeah. Currently not working for me, either. Though I didn't change PT version. Still on 2022.10.0

                                      1. Kitch Membery @Kitch2023-03-19 20:52:40.427Z

                                        Hi Mark,

                                        Can you take a screen recording so I can see where this script is failing. Hopefully that'll help me troubleshoot it. :-)

                                    • M
                                      In reply toMark_Mangini:
                                      Mark Mangini @Mark_Mangini
                                        2023-03-19 21:30:52.190Z

                                        Sure. Hang on a minute...

                                        1. Kitch Membery @Kitch2023-03-19 21:39:30.589Z

                                          I spoke too soon... Was able to recreate the quirky issue. I think I have a fix for it. Stand by. :-)

                                        2. M
                                          In reply toMark_Mangini:
                                          Mark Mangini @Mark_Mangini
                                            2023-03-19 21:41:30.532Z

                                            I am discovering that it is session sensitive. I opened a new session with no audio and it worked fine. I opened a work session from the project I am on that has a lot of tracks and it doesn't work.

                                            1. Kitch Membery @Kitch2023-03-19 21:42:59.215Z

                                              Thanks Mark... Take note of the two sessions to test my new version with. (Still working on it) :-)

                                              1. In reply toMark_Mangini:
                                                Kitch Membery @Kitch2023-03-19 21:52:07.261Z

                                                Quick question... If you perform this manually, Do you select the "Relink Offline" or "Relink" menu item from the ptx session right click?

                                                I'm asking because for me, clicking the "Relink Offline" button does not open the "Relink" window but clicking the "Relink" menu opens the "Relink" window.

                                                1. In reply toMark_Mangini:
                                                  Kitch Membery @Kitch2023-03-19 21:53:20.667Z

                                                  This is the menu I'm talking about.

                                                  1. Kitch Membery @Kitch2023-03-19 22:03:47.789Z

                                                    Try this @Mark_Mangini,

                                                    const relinkMenuOption = "Relink Offline";
                                                    
                                                    const sessionPath = sf.ui.proTools.mainWindow.sessionPath;
                                                    const sessionName = sessionPath.split('/').slice(-1)[0].split('.').slice(0, -1).join('.');
                                                    
                                                    function openWorkspace() {
                                                        const win = sf.ui.proTools.windows.whoseTitle.startsWith("Workspace: ").first;
                                                    
                                                        //If a workspace window is not open, open it.
                                                        if (!win.exists) {
                                                            sf.keyboard.press({ keys: "alt+o", });
                                                        }
                                                    
                                                        //Wait for Worksapce window
                                                        win.elementWaitFor();
                                                    }
                                                    
                                                    function openRelinkWindow() {
                                                        let win = sf.ui.proTools.windows.whoseTitle.startsWith("Workspace: ").first;
                                                        win.elementRaise();
                                                        let textGrid = win.tables.whoseTitle.is("TextGridView").allItems[1];
                                                        let rows = textGrid.children.whoseRole.is("AXRow");
                                                        let sessionRow = rows.filter(e => e.children.first.children.first.title.invalidate().value === sessionName)[0];
                                                    
                                                        //Open right click popup menu
                                                        let sessionRowPopUpMenu = sessionRow.childrenByRole("AXCell").first.popupMenuOpenFromElement({
                                                            isRightClick: true,
                                                        }).popupMenu;
                                                    
                                                        const relinkOflineMIPosition = sessionRowPopUpMenu.menuFetchAllItems().menuItems.filter(mi => mi.path[0] === relinkMenuOption)[0].element.position;
                                                    
                                                        //Get the current mouse position
                                                        const oldMousePosition = sf.mouse.getPosition().position;
                                                    
                                                        //Click the menu item
                                                        sf.mouse.setPosition({ position: relinkOflineMIPosition, });
                                                        sf.mouse.click({ position: relinkOflineMIPosition, });
                                                    
                                                        //Return mouse position
                                                        sf.mouse.setPosition({ position: oldMousePosition });
                                                    
                                                        //Wait for relink window to appear
                                                        sf.ui.proTools.windows.whoseTitle.is("Relink").first.elementWaitFor();
                                                    
                                                        //Close Workspace window
                                                        win.windowClose();
                                                    
                                                        //Wait for Workspace window to disappear
                                                        win.elementWaitFor({ waitType: 'Disappear' });
                                                    }
                                                    
                                                    function main() {
                                                        //Activate Pro Tools Main Window
                                                        sf.ui.proTools.appActivateMainWindow();
                                                    
                                                        openWorkspace();
                                                    
                                                        openRelinkWindow();
                                                    }
                                                    
                                                    main();
                                                    

                                                    If that does not work, change the first line of the script to...

                                                    const relinkMenuOption = "Relink";
                                                    
                                                    

                                                    And try again.

                                                2. M
                                                  In reply toMark_Mangini:
                                                  Mark Mangini @Mark_Mangini
                                                    2023-03-19 21:57:45.924Z

                                                    I don't even know where that menu is. I have only used the SoundFlow script.

                                                    1. Kitch Membery @Kitch2023-03-19 21:58:49.954Z

                                                      Its in the workspace menu when right clicking the PTX file in the Locations column. :-)

                                                    2. M
                                                      In reply toMark_Mangini:
                                                      Mark Mangini @Mark_Mangini
                                                        2023-03-19 21:59:02.354Z

                                                        I don't even know where that menu is. I have only used the SoundFlow script. This be as a consequence of having closed the ReLink window after opening a session, then wanting to re-open it.

                                                        1. M
                                                          In reply toMark_Mangini:
                                                          Mark Mangini @Mark_Mangini
                                                            2023-03-19 21:59:46.386Z

                                                            Most people don't know that, including myself. A truly hidden feature.

                                                            1. M
                                                              In reply toMark_Mangini:
                                                              Mark Mangini @Mark_Mangini
                                                                2023-03-19 22:18:01.806Z

                                                                This is a strange behavior. When I run the RELINK script, it fails and I get a Soundflow error message saying it couldn't run for 2000s. I then close the workspace window, and the relink window pops up.

                                                                1. Kitch Membery @Kitch2023-03-19 22:20:38.265Z

                                                                  Hmmm The Relink window might have been open but behind the edit window. Can you try closing all instances of the "Workspace" and the "Relink" windows and try running the script?

                                                                2. M
                                                                  In reply toMark_Mangini:
                                                                  Mark Mangini @Mark_Mangini
                                                                    2023-03-19 22:28:11.573Z

                                                                    Nope, not the problem. But it appears to be related to window priorities. When I open a session and click the RELINK macro, it fails and I g

                                                                    click to show
                                                                    1. M
                                                                      In reply toMark_Mangini:
                                                                      Mark Mangini @Mark_Mangini
                                                                        2023-03-19 22:50:54.729Z

                                                                        I can’t seem to make a JPEG screen recording. QT only makes .mov

                                                                        1. Kitch Membery @Kitch2023-03-19 22:52:55.046Z

                                                                          No worries, Mark,

                                                                          I'm back at my Desktop computer now so I'll see if I can recreate the issue in PT 2022.10