No internet connection
  1. Home
  2. Macro and Script Help

Delete Track command stopped working.

By Zach Moody @Zach_Moody
    2022-04-12 15:45:19.705Z

    Title

    Delete Track command stopped working.

    What do you expect to happen when you run the script/macro?

    I'm writing a script to automate cleaning up my session to send to the client after the record. So far I had it renaming the session, selecting the Routing folder and some other tracks to delete,and deleting them. There is a folder full of tracks that gets deleted so a window pops up asking if I want to keep or delete the tracks inside the folder. I have the script waiting for that and selecting delete. Since some of the other tracks have clips in them Pro Tools then pops up a window telling me there are clips in some of the tracks. I was working on this code when the delete tracks stopped working. Now when I run the script it doesn't try to delete any tracks. I just get an error that it timed out waiting for the window to pop up. I don't think I changed anything else. I'm sure i'm missing something.

    Are you seeing an error?

    The script is not running the delete tracks command and is timing out waiting for the window that pops up when delete tracks is run.

    What happens when you run this script?

    It selects the correct tracks but doesn't try to delete them.

    How were you running this script?

    I used a keyboard shortcut within the target app

    How important is this issue to you?

    4

    Details

    {
        "inputExpected": "I'm writing a script to automate cleaning up my session to send to the client after the record. So far I had it renaming the session, selecting the Routing folder and some other tracks to delete,and deleting them. There is a folder full of tracks that gets deleted so a window pops up asking if I want to keep or delete the tracks inside the folder. I have the script waiting for that and selecting delete. Since some of the other tracks have clips in them Pro Tools then pops up a window telling me there are clips in some of the tracks. I was working on this code when the delete tracks stopped working. Now when I run the script it doesn't try to delete any tracks. I just get an error that it timed out waiting for the window to pop up. I don't think I changed anything else. I'm sure i'm missing something. ",
        "inputIsError": true,
        "inputError": "The script is not running the delete tracks command and is timing out waiting for the window that pops up when delete tracks is run.",
        "inputWhatHappens": "It selects the correct tracks but doesn't try to delete them.",
        "inputHowRun": {
            "key": "-Mpfwh4RkPLb2LPwjePT",
            "title": "I used a keyboard shortcut within the target app"
        },
        "inputImportance": 4,
        "inputTitle": "Delete Track command stopped  working."
    }

    Source

    // Save file as with Prep prefix
    
    //Get our filename without extension
    var fileNameWithoutExtension = sf.ui.proTools.mainWindow.invalidate().sessionPath.split('/').slice(-1)[0].split('.').slice(0, -1).join('.');
    //Invoke File Save As.
    sf.ui.proTools.getMenuItem('File', 'Save As...').elementClick();
    //Wait for the Save dialog to appear
    var dlg = sf.ui.proTools.windows.invalidate().whoseTitle.is('Save').first.elementWaitFor().element;
    //Enter the new name
    dlg.textFields.first.value.value = 'Prep_' + fileNameWithoutExtension;
    //Click Save
    dlg.buttons.whoseTitle.is('Save').first.elementClick();
    
    //Reset SF Cache
    sf.ui.proTools.mainWindow.invalidate();
    
    //Select tracks to delete
    function selectTracksByNameWithWildcard(trackNames = []) {
    
        function matchWildcard(str, rule) {
            var escapeRegex = (str) => str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
            return new RegExp("^" + rule.split("*").map(escapeRegex).join(".*") + "$", "i").test(str);
        }
    
        var allNames = sf.ui.proTools.trackNames;
    
        var namesToSelect = allNames.filter(n => trackNames.some(tn => matchWildcard(n, tn)));
    
        sf.ui.proTools.trackSelectByName({
            names: namesToSelect,
            deselectOthers: true,
        });
    }
    selectTracksByNameWithWildcard([
        'Master 1',
        'Aux 1',
        'ROUTING',
        '*ISO*'
    ]);
    
    //Delete selected tracks
    sf.ui.proTools.trackDelete();
    
    //Confirm deletion of all tracks in ROUTING folder
    sf.ui.proTools.confirmationDialog.invalidate().elementWaitFor();
    sf.ui.proTools.confirmationDialog.buttons.whoseTitle.is("Delete").first.elementClick();
    
    //Confirm deletion of tracks with clips on them
    sf.ui.proTools.confirmationDialog.invalidate().elementWaitFor();
    sf.ui.proTools.confirmationDialog.buttons.whoseTitle.is("Delete").first.elementClick();
    
    

    Links

    User UID: PK7MrNcgoyUfepXBHxbD9Uvnheh2

    Feedback Key: sffeedback:PK7MrNcgoyUfepXBHxbD9Uvnheh2:-N-TRpwLQ2P5G1hthZGo

    Feedback ZIP

    Solved in post #2, click to view
    • 4 replies
    1. Try adding this right before deleting the tracks:

      // Force menu item state to refresh by pressing an arbitrary key
      sf.keyboard.press({ keys: "left" });
      
      ReplySolution
      1. Z
        In reply toZach_Moody:
        Zach Moody @Zach_Moody
          2022-04-12 20:12:39.903Z

          That worked perfectly Raphael. Thank you so much.
          If you don't mind me asking. What is this doing, other than pressing the left key?

          1. Good!

            Yeah, I'll explain. What's happening here is that we're sending a keypress to force Pro Tools to update its menu items. The left arrow is usually a safe key to press since it won't do anything adverse in the flow of this script. The reason why we need to do this is because Pro Tools sometimes will not update menu items while being automated. What the trackDelete() function is doing is activating the action on the Track > Delete menu item, but in this case, that menu item would be disabled (grayed out) since Pro Tools has not refreshed its state after coming off from the Save dialog. Simulating any key press gets it to work normally again.

            Hope that makes sense!

          2. Z
            In reply toZach_Moody:
            Zach Moody @Zach_Moody
              2022-04-13 18:34:00.173Z

              Thanks for the explanation Raphael.