No internet connection
  1. Home
  2. How to

How To Make User Text Prompt

By Phil McGowan @Phil_McGowan
    2020-12-13 03:41:00.688Z

    Hi,
    I can't find where to add a user prompt for text.

    I'm trying to recreate my stem renamer macro that I have built in Keyboard Maestro in SoundFlow, wondering if it is even possible.

    Here is what I have in KM:

    The looping I can probably work out from the SoundFlow loop video on YouTube but I still haven't figured out how to get that initial window to pop up so I can essentially set the clipboard.

    Thanks!

    Solved in post #6, click to view
    • 28 replies

    There are 28 replies. Estimated reading time: 20 minutes

    1. Hi Phil,

      You can definitely make a stem renamer in SF :) And much more powerfully than your original.

      You can do a prompt in SF with prompt(), like this, and then store it in the clipboard:

      var cueNumberAndTitle = prompt(`Enter Cue Number & Title`);
      sf.clipboard.setText({ text: cueNumberAndTitle });
      

      However – with SoundFlow you won't have to overwrite the clipboard at all to do these kinds of things.
      You can directly manipulate and automate the individual actions you need.

      We also don't use keyboard simulation unless absolutely necessary.

      You can learn more about how to use UI automation instead of keyboard simulation in the following 2 videos:

      1. You can also combine it with the following action to repeat your steps for each selected clip, if you need to make changes to many individual stems.

        A good way to get help to write the script is if you can tell us the overall workflow you'd like to achieve.
        Quite often, the experienced SF scripters here would be able to help find the best possible way to automate it, but we'll need to understand in more detail exactly what you intend the script to do (we can't read that out of the keyboard sequence you have in your KM script).

        1. Phil McGowan @Phil_McGowan
            2020-12-14 23:53:28.639Z

            Hey Christian,
            Thanks! I'll see what I can do with that prompt for the cue name.

            What I need it to do is actually pretty simple:

            1. Open a prompt and ask for the Cue Name to be pasted into each clip name (with an "OK" or "Cancel" button in case I click the wrong one
            2. Click Menu Item "Rename..." in the "Clip" menu. (that's easy)
            3. Delete the extra characters Pro Tools adds to the freshly recorded clip. Usually it's 3 characters ("A Orch_11" would need "_11" removed)
            4. Paste the text from the prompt at the beginning of the file name and add a space. (For the above example "A Orch_11" would now be "Prompted Text A Orch")
            5. Click OK UI element and repeat until the "Name" window disappears.

            Now the above actions work with the script I have in KM until you start to make playlists of the stem tracks. 3 extra characters are added at the end (.01) and now need to be removed when I print a new mix version into the upped playlist, so at the moment I have a 2nd script and key command for Playlist 1 and beyond that just hits delete 3 more times. I'm sure this could be done more elegantly but the programming for SF to identify that you're in a new playlist feels beyond me.

            I would be fine for now to just have the above steps in a Soundflow script where I can easily modify the number of text deletions to make other renamers until some sort of logic is scripted though I'm not even sure specifically what I would want soundflow to discover...

            Also to note, anyone reading this thinking "why doesn't he just use the built in PT batch renamer", sadly it doesn't rename the file name for some reason so I'm resorting to continuing to use my scripts that were built before batch rename was a feature. Once Pro Tools adds the oh so simple check box "rename filename" to the batch renamer I won't need this script per se but for now, it is what it is.

            1. Hi Phil,

              How are the clips laid out that you need to rename this way? Are they all each on a separate track, and all within the selection – like recorded stems? Can you share a screenshot?

              1. Phil McGowan @Phil_McGowan
                  2020-12-15 00:48:17.254Z

                  Oh yea, to answer your question here, yes they're all on separate tracks in a group so they're all within a selection.

          • In reply toPhil_McGowan:
            Phil McGowan @Phil_McGowan
              2020-12-15 00:39:11.018Z

              Ok yay I figured out a working script!

              I'm sure this can be refined but here's what I've got:

              sf.ui.proTools.appActivateMainWindow();
              
              var cueNumberAndTitle = prompt(`Enter Cue Number, Title, Version, & Mix Version`);
              sf.clipboard.setText({ text: cueNumberAndTitle });
              
              sf.ui.proTools.menuClick({
                  menuPath: ["Clip", "Rename..."],
              });
              
              sf.ui.proTools.windows.whoseTitle.is('Name').first.elementWaitFor();
              
              do {
              
                  sf.keyboard.press({
                      keys: "down, backspace, backspace, backspace, backspace, up",
                      fast: true,
                  });
              
                  sf.keyboard.type({
                      text: cueNumberAndTitle,
                  });
              
                  sf.keyboard.press({
                      keys: "space",
                  });
              
                  sf.ui.proTools.windows.whoseTitle.is('Name').first.buttons.whoseTitle.is('OK').first.elementClick();
              
                  sf.wait({
                      intervalMs: 50,
                  });
              } while (sf.ui.proTools.windows.whoseTitle.is('Name').first.uiElement);```
              ReplySolution
              1. Phil McGowan @Phil_McGowan
                  2020-12-15 00:45:25.646Z

                  So this works great and executes way faster than the keyboard maestro one did, I can now finally shut down KM and do all my key commands and macros in soundflow!

                  The only issue i'm having with this isn't really an issue, but maybe there's a way to fix this. If I hit "cancel" in the variable prompt that comes up, the script fails where I'd basically just like it to stop. All that happens of course is that a fail notification comes up, which is totally fine, but it would be slick for that not to happen.

                  1. Raphael Sepulveda @raphaelsepulveda2020-12-15 05:34:04.895Z2020-12-16 01:00:53.914Z

                    Hey Phil!

                    That script is looking good! Here is my take on it taking into consideration the things you mentioned above.

                    • This script will prompt you for input with a dialog box that cancels silently if you press it.
                    • It will delete any number of characters from the last underscore onwards, so you don't have to have two different scripts!
                    sf.ui.proTools.appActivateMainWindow();
                    
                    let clipName;
                    let newClipName;
                    let nameWin = sf.ui.proTools.windows.whoseTitle.is('Name').first;
                    
                    // User input
                    const cueNumberAndTitle = sf.interaction.displayDialog({
                        buttons: ['Ok', 'Cancel'],
                        defaultButton: 'Ok',
                        cancelButton: 'Cancel',
                        prompt: 'Enter Cue Number, Title, Version, & Mix Version',
                        defaultAnswer: '',
                    }).text;
                    
                    sf.ui.proTools.menuClick({ menuPath: ["Clip", "Rename..."], });
                    
                    nameWin.elementWaitFor();
                    
                    // Rename clips
                    while (!sf.ui.proTools.getMenuItem('Clip', 'Rename...').isEnabled) {
                        clipName = nameWin.invalidate().groups.whoseTitle.is('Name').first.textFields.first.value.value;
                        newClipName = cueNumberAndTitle + ' ' + clipName.replace(/_(?!.*_).*|\.(?!.*\.).*/, '');
                    
                        nameWin.groups.whoseTitle.is('Name').first.textFields.first.elementSetTextFieldWithAreaValue({
                            value: newClipName,
                        });
                        nameWin.buttons.whoseTitle.is('OK').first.elementClick();
                    };
                    

                    Give it a try and let me know how it runs on your system!

                    1. Great work guys!

                      One thing I would add is that right now you're relying on the fact that running Clip -> Rename... will iterate through all the selected clips for you and keep the dialog open for every clip.
                      If all selected clips are always one clip per track (for stem recording), then you could also get the number of clips from it (equal to the number of tracks), and then loop through opening/closing the Clip Rename dialog one clip at a time, selecting each track one at a time with Link Edit and Track Selection on. This way you wouldn't have to rely on timing at all, so it could be a little more stable. But your method is likely faster, just slightly more reliant on that manual wait.

                      1. The one thing you could do with the wait would be to wait for the clip name in the text field to have updated. Then you could go with a short wait, or even no wait, and then continue waiting until the clip name in the text field had updated (marking that you're now at the next clip).

                        1. Raphael Sepulveda @raphaelsepulveda2020-12-15 19:38:49.810Z2020-12-15 19:47:39.436Z

                          Thanks for the suggestions, @chrscheuer ! Without the wait() I kept getting an error during the while loop since there seems to be an incredibly small delay between the detection of the new value and the Rename window closing, but I was able to overcome it by checking for the enable status of the 'Rename...' menu item instead. I've revised my script above. No more manual wait times and still very fast!

                      2. Phil McGowan @Phil_McGowan
                          2020-12-15 23:38:57.162Z

                          Thanks Raphael, I'll check this out and see if it works to integrate it into my script!

                          I will need to add a single backspace since I name my stem record tracks with an extra character at the end so I can have an A/B roll. So my first stem, for example, is "A Orcha" and the same stem in the B roll would be "A Orchb" and my script gets rid of the "a" or "b" at the end of the filename as I wouldn't want it in there.

                          Thanks again!

                          1. Phil McGowan @Phil_McGowan
                              2020-12-15 23:50:13.889Z

                              Ok I just tried your script and the new prompt is perfect!

                              When I make a new playlist and rename though, it doesn't get rid of the ".01" so for now I'm going to integrate your prompt box into my 2 scripts and carry on with those.

                              Thanks again!
                              -Phil

                              1. Ah, my bad! The script was looking for the last underscore and everything after that, but when you create a new playlist the period is before the underscore [facepalm]. I've updated the script above to handle both cases.

                                Regarding the roll versions, if you replace this part clipName.replace(/_(?!.*_).*|\.(?!.*\.).*/, '') with this clipName.replace(/[ab]?_(?!.*_).*|[ab]?\.(?!.*\.).*/, '') it will also delete any 'a' or 'b' that it encounters right before the last period or underscore.

                                Sorry to bombard you with options, haha. Just want to make sure you're leveraging the power of SoundFlow. But in the end, whatever gets the job done!

                                1. Phil McGowan @Phil_McGowan
                                    2020-12-16 01:38:23.965Z

                                    Ok sweet that's getting close!

                                    It's not always an "a" or "b" though so I would need it to delete the final character of the track name no matter what.

                                    For example, I might make a 3rd "c" pass or if I'm mixing with 1 session per cue instead of a Reel session, I add a "+" to to the end of my track names so the renamer will have something to delete.

                                    Is there a way to script it just deleting 1 character no matter what? The equivalent of hitting backspace once.

                                    Other than that this is working well, thanks!

                                    1. If that's the case, it's even easier: clipName.replace(/._(?!.*_).*|.\.(?!.*\.).*/, '') will do just that!

                                      1. Phil McGowan @Phil_McGowan
                                          2020-12-16 02:17:40.069Z

                                          Perfect, this works great, thanks!

                                          1. Phil McGowan @Phil_McGowan
                                              2020-12-16 21:31:56.798Z

                                              Ah bummer, now that I'm doing a surround mix we have a bug.

                                              It removes "5.1 Mix" from my file name due to the period.

                                              I wonder if there's any other way to remove the playlist numbers other than doing the keyboard commands....

                                              1. I believe @raphaelsepulveda could add a an alternate routine if this condition is met:
                                                if(clipName.endsWith('5.1 Mix') { // ALTERNATE RENAME ROUTINE HERE}

                                                1. In reply toPhil_McGowan:

                                                  Oh no! What does the file name look like right before you run the rename script?

                                                  1. Phil McGowan @Phil_McGowan
                                                      2020-12-17 01:54:17.740Z

                                                      The Track name is "F 5.1 Mixa" so the file name after a print would be "F 5.1 Mixa_01"

                                                      Let's say I enter "WI 1m1 x1" as the cue number, the script will rename it to "WI 1m1 x1 F" instead of "WI 1m1 x1 F 5.1 Mix"

                                                      1. In reply toPhil_McGowan:

                                                        Update: Previously I had posted a more elaborate solution, but one sleep later, a much more simple solution dawned on me:
                                                        clipName.replace(/.\.(?!.*\.)\d{2}.*|._(?!.*_).*/, '')
                                                        This will take care of any naming situation I can think of. Let me know how it goes!

                                                        1. Phil McGowan @Phil_McGowan
                                                            2020-12-17 18:17:40.239Z

                                                            Yes, that works!

                                                            I knew there had to be a universal way to do it, I'm just a total Java/Programming n00b!

                                                            Thanks so much for all your help!

                                                            1. Perfect! No problem at all!

                                    2. In reply toPhil_McGowan:
                                      Phil McGowan @Phil_McGowan
                                        2020-12-17 18:42:02.053Z

                                        Here's the (probably) final script for anyone interested:

                                        sf.ui.proTools.appActivateMainWindow();
                                        
                                        let clipName;
                                        let newClipName;
                                        let nameWin = sf.ui.proTools.windows.whoseTitle.is('Name').first;
                                        
                                        // User input
                                        const cueNumberAndTitle = sf.interaction.displayDialog({
                                            buttons: ['Ok', 'Cancel'],
                                            defaultButton: 'Ok',
                                            cancelButton: 'Cancel',
                                            prompt: 'Enter Cue Number, Title, Version, & Mix Version',
                                            defaultAnswer: '',
                                        }).text;
                                        
                                        sf.ui.proTools.menuClick({ menuPath: ["Clip", "Rename..."], });
                                        
                                        nameWin.elementWaitFor();
                                        
                                        // Rename clips
                                        while (!sf.ui.proTools.getMenuItem('Clip', 'Rename...').isEnabled) {
                                            clipName = nameWin.invalidate().groups.whoseTitle.is('Name').first.textFields.first.value.value;
                                            newClipName = cueNumberAndTitle + " " + clipName.replace(/.\.(?!.*\.)\d{2}.*|._(?!.*_).*/, '');
                                        
                                            nameWin.groups.whoseTitle.is('Name').first.textFields.first.elementSetTextFieldWithAreaValue({
                                                value: newClipName,
                                            });
                                            nameWin.buttons.whoseTitle.is('OK').first.elementClick();
                                        };
                                        1. Phil McGowan @Phil_McGowan
                                            2020-12-17 18:43:29.098Z

                                            Ok one small change lol, changed the "Ok" button to "Rename"

                                            sf.ui.proTools.appActivateMainWindow();
                                            
                                            let clipName;
                                            let newClipName;
                                            let nameWin = sf.ui.proTools.windows.whoseTitle.is('Name').first;
                                            
                                            // User input
                                            const cueNumberAndTitle = sf.interaction.displayDialog({
                                                buttons: ['Rename', 'Cancel'],
                                                defaultButton: 'Rename',
                                                cancelButton: 'Cancel',
                                                prompt: 'Enter Cue Number, Title, Version, & Mix Version',
                                                defaultAnswer: '',
                                            }).text;
                                            
                                            sf.ui.proTools.menuClick({ menuPath: ["Clip", "Rename..."], });
                                            
                                            nameWin.elementWaitFor();
                                            
                                            // Rename clips
                                            while (!sf.ui.proTools.getMenuItem('Clip', 'Rename...').isEnabled) {
                                                clipName = nameWin.invalidate().groups.whoseTitle.is('Name').first.textFields.first.value.value;
                                                newClipName = cueNumberAndTitle + " " + clipName.replace(/.\.(?!.*\.)\d{2}.*|._(?!.*_).*/, '');
                                            
                                                nameWin.groups.whoseTitle.is('Name').first.textFields.first.elementSetTextFieldWithAreaValue({
                                                    value: newClipName,
                                                });
                                                nameWin.buttons.whoseTitle.is('OK').first.elementClick();
                                            };
                                          • In reply toPhil_McGowan:
                                            Phil McGowan @Phil_McGowan
                                              2023-03-17 17:16:22.229Z

                                              Hey All,
                                              Thanks again so much for your help building this script!

                                              Sadly, it's stopped working. Seems like it's either a new PT version or new MacOS bug.

                                              The text prompt comes up but after I hit enter, nothing at all happens, not even an error.

                                              Ideas?

                                              1. Make sure to clear search on your clip bin? That's gotten me a number of times on similar things... maybe that's it?