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

how do i make a script to "record enable a selected track"?

By Mert B @Mert_B
    2024-05-20 20:59:01.397Z

    Title

    how do i make a script to "record enable a selected track"?

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

    record enable a selected track

    Are you seeing an error?

    // Soundflow Script to Record Enable Selected Track in Pro Tools

    // Make sure Pro Tools is the active application
    sf.ui.proTools.appActivateMainWindow();

    // Get the selected track
    let track = sf.ui.proTools.selectedTrack;

    // Check if a track is selected
    if (track.exists) {
    // Focus on the track to ensure it is selected
    track.trackScrollToView();

    // Find the record enable button for the selected track
    let recordEnableButton = track.buttons.filter(button => button.role == "AXRecordEnableButton");
    
    // Check if the record enable button exists
    if (recordEnableButton.length > 0) {
        // Enable record on the selected track
        recordEnableButton[0].elementClick();
    
        // Confirm that the track is record enabled
        recordEnableButton[0].elementExists().assertTrue("Record Enable button not found");
    } else {
        // If the record enable button is not found, show a message
        sf.ui.showModalMessage("Record Enable button not found on the selected track.");
    }
    

    } else {
    // If no track is selected, show a message
    sf.ui.showModalMessage("No track is selected. Please select a track first.");
    }

    What happens when you run this script?

    i get an error

    How were you running this script?

    I used a Stream Deck button

    How important is this issue to you?

    3

    Details

    {
        "inputExpected": "record enable a selected track",
        "inputIsError": true,
        "inputError": "// Soundflow Script to Record Enable Selected Track in Pro Tools\n\n// Make sure Pro Tools is the active application\nsf.ui.proTools.appActivateMainWindow();\n\n// Get the selected track\nlet track = sf.ui.proTools.selectedTrack;\n\n// Check if a track is selected\nif (track.exists) {\n    // Focus on the track to ensure it is selected\n    track.trackScrollToView();\n\n    // Find the record enable button for the selected track\n    let recordEnableButton = track.buttons.filter(button => button.role == \"AXRecordEnableButton\");\n\n    // Check if the record enable button exists\n    if (recordEnableButton.length > 0) {\n        // Enable record on the selected track\n        recordEnableButton[0].elementClick();\n\n        // Confirm that the track is record enabled\n        recordEnableButton[0].elementExists().assertTrue(\"Record Enable button not found\");\n    } else {\n        // If the record enable button is not found, show a message\n        sf.ui.showModalMessage(\"Record Enable button not found on the selected track.\");\n    }\n} else {\n    // If no track is selected, show a message\n    sf.ui.showModalMessage(\"No track is selected. Please select a track first.\");\n}\n\n",
        "inputWhatHappens": "i get an error",
        "inputHowRun": {
            "key": "-MpfwmPg-2Sb-HxHQAff",
            "title": "I used a Stream Deck button"
        },
        "inputImportance": 3,
        "inputTitle": "how do i make a script to \"record enable a selected track\"?"
    }

    Source

    // Soundflow Script to Record Enable Selected Track in Pro Tools
    
    // Make sure Pro Tools is the active application
    sf.ui.proTools.appActivateMainWindow();
    
    // Get the selected track
    let track = sf.ui.proTools.selectedTrack;
    
    // Check if a track is selected
    if (track.exists) {
        // Focus on the track to ensure it is selected
        track.trackScrollToView();
    
        // Find the record enable button for the selected track
        let recordEnableButton = track.buttons.filter(button => button.role == "AXRecordEnableButton");
    
        // Check if the record enable button exists
        if (recordEnableButton.length > 0) {
            // Enable record on the selected track
            recordEnableButton[0].elementClick();
    
            // Confirm that the track is record enabled
            recordEnableButton[0].elementExists().assertTrue("Record Enable button not found");
        } else {
            // If the record enable button is not found, show a message
            sf.ui.showModalMessage("Record Enable button not found on the selected track.");
        }
    } else {
        // If no track is selected, show a message
        sf.ui.showModalMessage("No track is selected. Please select a track first.");
    }
    
    

    Links

    User UID: EgPyQseHgSSkiacsRXj63EuYzvi1

    Feedback Key: sffeedback:EgPyQseHgSSkiacsRXj63EuYzvi1:-NyMnDwzUmlAoBZuRd2x

    Feedback ZIP: xE6ZN1dB5C4WdqRLuthenSWicOZRgt2Zh+FCJtRvW9R2S7LpvGrh8LpiFwC03DQw2iMBJE8H9jrD+XknY9hcbZJ4hJffXJOcqPfm35ucEJWjjluCqgEsmnNkxQQKwGKGz4nm7fInaGWiY3ID4ulBr9TAipwg3oQoCR4BT64KqlW4KLWh1iulpCawBZAy1d2lv7VLZjcfgOXNBSPdMl2w7lqm+pX/vZxr8UN0xj/V9yYogGDC1fTCWJU3iO8bWGHj4gyBnvAV08AgRu2dlf9/gZ6faaeMYd76rKlihutClQzsT1YnrQgwgSbJMBTXA3U5Ybx/5ouFCp7gwTlnLLQDDXqK3JnRuNlBcvk0lr22EZk=

    • 2 replies
    1. Chris Shaw @Chris_Shaw2024-05-21 20:01:54.604Z2024-05-21 20:09:12.912Z

      It seems as if you're trying to use JavaScript properties and methods that don't exist in SF (elementExists, showModalMessage and assertTrue

      Try this:

      sf.ui.proTools.appActivateMainWindow();
      
      // Check for selected Tracks
      if (sf.ui.proTools.selectedTracks.count == 0) {
          log("No Track(s) Selected")
          throw 0
      }
      
      // Get first selected Track
      let selectedTrack = sf.ui.proTools.selectedTrack;
      
      //Get record button (if any)
      const recordButton = selectedTrack.buttons.whoseTitle.is("Track Record Enable").first;
      
      // try pressing record button
      let wasRecButtonPressed = recordButton.elementClick({onError:"Continue"}).success;
      if (!wasRecButtonPressed) log("Record button not found on selected Track")
      

      I'm assuming you're using this as part of a larger script / workflow.
      If all you want to do is record enable a selected track with a keyboard trigger you could always use shift +r which is the built in PT shortcut

      1. Also it's not necessary to scroll a track into view to press the record button. As long as it is visible in the edit window - even if it is scrolled off screen - it'll be pressed