No internet connection
  1. Home
  2. How to

Manualy Find and relink macro

By Alberto Cruz @Alberto_Cruz
    2023-05-10 06:14:21.142Z2023-05-12 23:04:45.098Z

    Hello!

    Trying to save myself some clicks, and stumped myself.

    Want to make a simple script that automates some of the bit of opening a session. Im receiving a bunch of sessions from a scoring stage with a large amount of missing files. These files exist in multiple places, and there is a LOT of stuff to get through, so its necessary to do a manual relink in order to prevent some weird stuff from happening and help things go a bit faster.

    Ive got something like this that I thought might work:

    sf.ui.proTools.appActivate();
    
    sf.ui.proTools.windows.whoseTitle.is("Missing Files").first.radioButtons.whoseTitle.is("Manually Find & Relink").first.elementClick();
    sf.ui.proTools.windows.whoseTitle.is("Missing Files").first.buttons.whoseTitle.is("OK").first.elementClick();
    
    sf.ui.proTools.windows.whoseTitle.is("Relink").first.elementWaitFor();
    sf.ui.proTools.windows.whoseTitle.is("Relink").first.buttons.whoseTitle.is("Find Links").first.elementClick();
    
    sf.ui.proTools.windows.whoseTitle.is("Linking Options").first.elementWaitFor();
    sf.ui.proTools.windows.whoseTitle.is("Linking Options").first.buttons.whoseTitle.is("OK").first.elementClick;
    

    Problem is, the "Find Links" Button apparently doesn't exist. And I'm not entirely sure how to get to that button for an element click.

    Maybe I'm just calling it wrong?

    Cant seem to be able to do a "pick" element on it either.

    How do I get to that button to click on it?

    • 1 replies
    1. Mike Wax @mikewax
        2025-08-13 16:42:52.730Z

        Hey @Alberto_Cruz,

        I came across this and was hoping i could help (if you're still in need of this).

        I have a script that basically takes imports all your audio from an AAF, then does work in the Relink window.
        I copied just the Relink window portion, but let me know if none of this makes sense.

        Hopefully this helps you out.

        // --- Wait for "MISSING FILES" to appear --- //
        const missingFilesWin = sf.ui.proTools.windows.whoseTitle.is("Missing Files").first;
        
        missingFilesWin.elementWaitFor({
            timeout: 2000,
            waitType: "Appear",
            onError: "ThrowError"
        }, `No files needed to be relinked.` );
        
        missingFilesWin.radioButtons.whoseTitle.is("Manually Find & Relink").first.elementClick();
        missingFilesWin.buttons.whoseTitle.is("OK").first.elementClick();
        
        // Wait for the Relink Window
        const relinkWin = sf.ui.proTools.windows.whoseTitle.is("Relink").first;
        relinkWin.elementWaitFor();
        
        sf.wait({ intervalMs: 100 });
        
        // Click the Preset #1.
        relinkWin.mouseClickElement({
            relativePosition: { "x": 67, "y": 45 },
        });
        
        sf.wait({ intervalMs: 100 });
        
        centerWindow({ window: relinkWin });
        
        
        
        // --- Show the client name. --- //
        const sessionPath = sf.ui.proTools.mainWindow.sessionPath.split('/').slice(0, -4).join('/');
        const clientName = sf.ui.proTools.mainWindow.sessionPath.split('/').slice(0, -4).join('/').slice(18).replace(/_/g, " ");
        
        sf.interaction.displayDialog({
            prompt: "Please select the client folder:\n" + clientName + "\n\nPress OK when done.",
            title: "Select Client Folder",
            buttons: ["OK", "Cancel"],
            defaultButton: "OK",
            onCancel: "Abort",
            cancelButton: "Cancel"
        });
        
        sf.wait({ intervalMs: 500 });
        
        relinkWin.mouseClickElement({
            relativePosition: {"x" : 200, "y" : 45}
        });
        
        // Linking Options
        const linkingOptionsWin = sf.ui.proTools.windows.whoseTitle.is("Linking Options").first;
        const matchFormat = sf.ui.proTools.windows.whoseTitle.is("Linking Options").first.checkBoxes.whoseTitle.is("Match Format").first;
        const matchDuration = sf.ui.proTools.windows.whoseTitle.is("Linking Options").first.checkBoxes.whoseTitle.is("Match Duration").first;
        const matchModDate = sf.ui.proTools.windows.whoseTitle.is("Linking Options").first.checkBoxes.whoseTitle.is("Match Modification Date").first;
        
        linkingOptionsWin.elementWaitFor();
        linkingOptionsWin.radioButtons.whoseTitle.is("Find By Name").first.elementClick();
        
        matchFormat.checkboxSet({ targetValue: "Disable" });
        matchModDate.checkboxSet({ targetValue: "Disable" });
        matchDuration.checkboxSet({ targetValue: "Disable" });
        
        // This is for the Confirmation Dialogue that shows up after you deselect "Match Duration".
        sf.ui.proTools.confirmationDialog.elementWaitFor({ waitType: 'Appear', timeout: 1000 });
        sf.ui.proTools.confirmationButtonDialog.buttons.whoseTitle.is("OK").first.elementClick();
        sf.ui.proTools.confirmationDialog.elementWaitFor({ waitType: 'Disappear' });
        
        linkingOptionsWin.buttons.whoseTitle.is("OK").first.elementClick();
        linkingOptionsWin.elementWaitFor({ waitType:"Disappear" });