No internet connection
  1. Home
  2. How to

Can't get elementSetTextFieldWithAreaValue to work in PT tempo change box

By Chris Winter @Chris_Winter
    2020-07-17 09:07:17.170Z

    I'm having an issue getting my text to actually change with elementSetTextFieldWithAreaValue in the ProTools Change Meter (Time Operations) window in the following script.
    All the window functions work fine, it's just I can't seem to make the text change in the box. Can someone please tell me where I'm going wrong?

    Many thanks,

    Chris

    // Sets ProTools meter to 3/4 at current location
    
    
    // Bring PT to Front
    sf.ui.proTools.appActivate();
    
    // Open Change Meter menu item
    sf.ui.proTools.menuClick({
        menuPath: ["Event","Time Operations","Change Meter..."],
    });
    
    // Wait for window to appear
    sf.ui.proTools.windows.whoseTitle.is('Time Operations').first.elementWaitFor();
    
    // Set first text box to 3
    sf.ui.proTools.windows.whoseTitle.is('Time Operations').first.textFields.whoseTitle.is('NumericEntryText').first.elementSetTextFieldWithAreaValue({
        value: "3",
    });
    
    // Set second text box to 4
    sf.ui.proTools.windows.whoseTitle.is('Time Operations').first.textFields.whoseTitle.is('NumericEntryText').allItems[1].elementSetTextFieldWithAreaValue({
        value: "4",
    });
    
    // Click apply
    sf.ui.proTools.windows.whoseTitle.is('Time Operations').first.buttons.whoseTitle.is('Apply').first.elementClick();
    
    // Close the window
    sf.ui.proTools.viewCloseFocusedFloatingWindow();
    
    // Wait for the window to close
    sf.ui.proTools.windows.whoseTitle.is('Time Operations').first.elementWaitFor({
        waitType: "Disappear",
    });
    
    Solved in post #4, click to view
    • 9 replies
    1. Hi Chris,

      Just a quick reply without having tested it myself.
      Certain text inputs in Pro Tools require you to click with the mouse on the text field and then simulate keyboard input. This typically is true for text inputs that are related to timing information (ie. bars|beats, timecode, min:secs, etc.)

      1. CChris Winter @Chris_Winter
          2020-07-17 09:11:31.113Z

          Ok, cool - I'll pursue that route.
          Thanks again for your time Christian!

          1. Kitch Membery @Kitch2020-07-17 10:35:16.272Z

            Hi Chris,

            Christian is correct... This should do it;

            //Activate Pro Tools Main Window
            sf.ui.proTools.appActivateMainWindow();
            
            //Click on New Meter's first field. 
            sf.ui.proTools.windows.whoseTitle.is('Time Operations').first.textFields.whoseTitle.is('NumericEntryText').first.elementClick();
            
            //Type "6"
            sf.keyboard.type({
                text: "6",
            });
            
            ReplySolution
            1. CChris Winter @Chris_Winter
                2020-07-17 11:12:14.465Z

                Thanks Kitch, I’ll try that when I get back to the studio tomorrow. In the meantime I got it to work click relative to the ui element.

                1. CChris Winter @Chris_Winter
                    2020-07-18 00:57:18.518Z

                    Thanks @Kitch and @chrscheuer! Works perfectly, and far more elegant than the click from a relative point option.

                  • In reply toKitch:
                    Ryan DeRemer @Ryan_DeRemer
                      2022-04-04 06:27:34.317Z

                      Hey @Kitch

                      I am having the same issue with the "Tempo Change" dialog. Trying to set the tempo in a new session based on the result of a dialog box at the start of the script. I got the tempo change window to open but can't seem to get the tempo filled in.

                      1. Kitch Membery @Kitch2022-04-04 06:33:13.971Z2022-04-04 08:33:37.706Z

                        Hi @Ryan_DeRemer,

                        Give this script a go;

                        It will ask for a new tempo, then set it based on the user input via the "Event"=>"Tempo Operations"=>"Constant..." window.

                        /** @param {string} bpm */
                        function updateTempoField(bpm) {
                            //Format the tempo to include 4 decimal places.
                            let newBpm = parseFloat(bpm).toFixed(4).toString();
                        
                            const win = sf.ui.proTools.windows.whoseTitle.is("Tempo Operations").first;
                            let bpmField = win.textFields.whoseTitle.is("NumericEntryText").allItems[2];
                        
                            win.elementWaitFor();
                        
                            if (bpmField.value.invalidate().value.trim() !== newBpm) {
                                bpmField.elementClick();
                        
                                //Clear Tempo field
                                sf.keyboard.press({ keys: "backspace", });
                        
                                //Enter in new bpm
                                sf.keyboard.type({ text: newBpm });
                        
                                var i = 0;
                        
                                while (bpmField.value.invalidate().value.trim() !== newBpm) {
                                    sf.wait({ intervalMs: 100 });
                                    i++
                                    if (i >= 20) { throw `Could not update number field` }
                                };
                        
                                //Apply the tempo
                                sf.ui.proTools.windows.whoseTitle.is("Tempo Operations").first.buttons.whoseTitle.is("Apply").first.mouseClickElement();
                        
                                win.windowClose();
                                win.elementWaitFor({ waitType: "Disappear" });
                            }
                        }
                        
                        function openTempoWindow() {
                            const win = sf.ui.proTools.windows.whoseTitle.is("Tempo Operations").first;
                        
                            if (!win.exists) {
                        
                                sf.ui.proTools.menuClick({
                                    menuPath: ["Event", "Tempo Operations", "Constant..."]
                                });
                        
                                win.elementWaitFor();
                            }
                        }
                        
                        function main() {
                            sf.ui.proTools.appActivateMainWindow();
                        
                            const newBpm = prompt("Please enter a new tempo.");
                        
                            openTempoWindow();
                        
                            updateTempoField(newBpm);
                        }
                        
                        main();
                        

                        Rock on!

                        1. Ryan DeRemer @Ryan_DeRemer
                            2022-04-04 16:59:37.939Z

                            @Kitch you freaking rock dude! Works perfectly! Now all I gotta do is integrate into the larger script.

                            The main script is for creating a new mix session, based on how I organize things in Finder and in PT. Would love your thoughts on making it into a template that folks could edit based on their workflow.

                            Essentially it creates a root directory in Finder to house the new session, changes the views and sorting to how I like it, and creates a subdirectory for file files the client sends me within the root directory. Then it creates a new PT session with my preferred settings and template, sets the tempo, then goes back to Finder and sets the views and sorting in the session folder as well. Could be useful for people, I know it's saving me a lot of work and clicking.

                            I'm working on getting it to set the Key Signature as well, but that's a whole other beast. Eventually I would like it to copy the client's files in to the appropriate folder from Downloads, and import them into the session as well.

                            What I have is working once I integrate the tempo command.

                            1. Kitch Membery @Kitch2022-04-04 17:30:48.571Z

                              My pleasure! And that sounds great @Ryan_DeRemer,

                              My suggestion would be to break down the workflow into parts, create scripts for each of the parts and test that they are working well, and once you have all the parts working, create functions for each part and join them together into one script.

                              And of course if you get stuck or have any questions, reach out to the community here in the forum :-)

                              Rock on!