No internet connection
  1. Home
  2. How to

How do I open selected files in the Finder in RX7?

By John Rammelt @John_Rammelt
    2019-09-10 13:49:48.547Z

    Maybe I'm thick but I can't get around opening files I have selected in the Finder in RX.
    I want to do this so I can run the Loudness Module with a Preset on the files and then Close and Save.

    Suggestions?

    BR,
    John

    Solved in post #12, click to view
    • 14 replies

    There are 14 replies. Estimated reading time: 18 minutes

    1. Hi @John_Rammelt

      You should be able to do that via this script:

      var path = decodeURIComponent(sf.appleScript.finder.selection.getItem(0).asItem.path);
      var izotopeRx = "/Applications/iZotope RX 6 Audio Editor.app";
      
      sf.system.exec({
          commandLine: 'open -a "' + izotopeRx + '" "' + path + '"'
      });
      

      Note how it needs the full path to the iZotope RX App in your applications folder - I have RX 6, so that's what I specified.

      1. Slight note: this will just open the 1st selected item. to open all selected items we'll need a slightly longer script.

        1. This script will open all selected files:

          
          function getSelectedPathsInFinder() {
              var count = sf.appleScript.finder.selection.length;
              var result = [];
              for(var i=0; i<count; i++) {
                  result.push(decodeURIComponent(sf.appleScript.finder.selection.getItem(i).asItem.path));
              }
              return result;
          }
          
          var paths = getSelectedPathsInFinder().map(function(p){ return '"' + p + '"'; }).join(" ");
          var izotopeRx = "/Applications/iZotope RX 6 Audio Editor.app";
          
          sf.system.exec({
              commandLine: 'open -a "' + izotopeRx + '" ' + paths + ''
          });
          
          1. JJohn Rammelt @John_Rammelt
              2019-09-10 14:49:43.523Z

              Yes! It works as expected, thank you.

              1. @John_Rammelt - great to hear!

                1. JJohn Rammelt @John_Rammelt
                    2019-09-11 12:11:32.259Z

                    OK, I could use some suggestion to what's wrong with this script so far.
                    Right now it doesn't open the Module, load the Preset nor Render it. I guess you shouldn't be trying to figure this stuff out while your actually working but I can't help myself ;-)
                    My ultimate goal is to be able to send several files to RX, apply the 'EBU_R128' Loudness Preset, close and save each one, one at a time.
                    The internal RX Batch processor adds '_1' to the filenames and saves as new files; I am not sure I can script sending into the Batch processor anyway.

                        var count = sf.appleScript.finder.selection.length;
                        var result = [];
                        for(var i=0; i<count; i++) {
                            result.push(decodeURIComponent(sf.appleScript.finder.selection.getItem(i).asItem.path));
                        }
                        return result;
                    }
                    
                    var paths = getSelectedPathsInFinder().map(function(p){ return '"' + p + '"'; }).join(" ");
                    var izotopeRx = "/Applications/iZotope RX 7 Audio Editor.app";
                    
                    sf.system.exec({
                        commandLine: 'open -a "' + izotopeRx + '" ' + paths + ''
                    });
                    sf.wait({ intervalMs: 1500 });
                    
                    function ensureModuleLoudnessIsOpen() {
                        var win = sf.ui.izotope.windows.whoseTitle.is('Loudness').first;
                        if (!win.exists) {
                            sf.ui.izotope.menuClick({
                                menuPath: ['Modules', 'Loudness...']
                            });
                            win.elementWaitFor();
                        }
                    }
                    
                    function selectModuleLoudnessPreset(name) {
                        var btn = sf.ui.izotope.windows.whoseTitle.is('Loudness').first.groups.whoseDescription.is('Loudness Panel').first.popupButtons.whoseDescription.is('Preset').first;
                        if (btn.value.invalidate().value == name) return;
                        btn.elementClick();
                        sf.keyboard.press({ keys: 'enter' });
                        while (true) {
                            sf.engine.checkForCancellation();
                            if (btn.value.invalidate().value == name) break;
                            sf.keyboard.press({ keys: 'down' });
                        }
                    }
                    function processOpenModuleLoudness() {
                        sf.ui.izotope.windows.whoseTitle.is('Loudness').first.groups.whoseDescription.is('Loudness Panel').first.buttons.whoseDescription.is('Render').first.elementClick();
                    }
                    
                    function processModuleLoudness(name) {
                        sf.ui.izotope.invalidate();
                        sf.ui.izotope.appActivateMainWindow();
                        ensureModuleLoudnessIsOpen();
                        selectModuleLoudnessPreset(name);
                        processOpenModuleLoudness();
                    
                    processModuleLoudness('EBU_R128');}
                    
                    1. one at a time

                      This may be part of the issue. I thought you wanted to open them all at once in iZotope. If you want to open a file, apply the processing and then close it, and first then move on to the next selected file, we'll need to do some restructuring of the script.
                      Just wanted to confirm if that's what you want before doing the work.

                      1. JJohn Rammelt @John_Rammelt
                          2019-09-11 19:34:38.605Z

                          Thanks so much for your patience and your help!
                          Well, I wanted to open them all at once in RX but process them one by one with my Loudness Module Preset. If I apply the Preset in Composite View the Loudness gets weird when they're all starting at the same point in time (I think that's why at least).

                          I was thinking that my script would:
                          open all selected files in the Finder (which it does, thank you) in RX,
                          then apply the Loudness Preset to the first selected/active file,
                          then close it and say 'yes' to 'do you wish to save it?'
                          After that check if there is another file open and apply the preset, close, save, etc until there is no file open.

                          Maybe Im naïve in thinking that it shouldn't be that hard to script it?

                          1. Gotcha! Well as you're pointing out, sometimes part of the complexity of writing scripts like this is that you find out along the way that you need to change a few things. You're right it should be possible to do this, but it's definitely not the simplest combination of commands I've seen someone take on haha :)
                            BUT, let's get it working. I could use a script like this myself haha!

                            1. JJohn Rammelt @John_Rammelt
                                2019-09-15 20:28:31.261Z

                                OK,
                                I'm slowly making progress here but I am still too unaccustomed to scripting.
                                Here's what I have so far:

                                //First checks for and closes all RX Connect windows that may be open
                                var compositeViewBtn = sf.ui.izotope.mainWindow.getFirstWithDescription('RX7 Main Window').getFirstWithDescription("Composite View");
                                if (compositeViewBtn.exists) compositeViewBtn.elementClick();
                                
                                var shuttleDiscardBtn = sf.ui.izotope.mainWindow.groups.whoseDescription.is('RX7 Main Window').first.buttons.whoseDescription.is('Shuttle Discard');
                                if (shuttleDiscardBtn.exists) shuttleDiscardBtn.first.elementClick();
                                
                                //This section opens selected files in the Finder in RX
                                function getSelectedPathsInFinder() {
                                    var count = sf.appleScript.finder.selection.length;
                                    var result = [];
                                    for(var i=0; i<count; i++) {
                                        result.push(decodeURIComponent(sf.appleScript.finder.selection.getItem(i).asItem.path));
                                    }
                                    return result;
                                }
                                
                                var paths = getSelectedPathsInFinder().map(function(p){ return '"' + p + '"'; }).join(" ");
                                var izotopeRx = "/Applications/iZotope RX 7 Audio Editor.app";
                                
                                sf.system.exec({
                                    commandLine: 'open -a "' + izotopeRx + '" ' + paths + ''
                                });
                                sf.wait({ intervalMs: 500 });
                                
                                //This section is supposed to check if the Loudness Module is open or not
                                //function ensureModuleLoudnessIsOpen() {
                                //    var win = moduleName = "Loudness";
                                //    if (!win.exists) {
                                //        sf.ui.izotope.menuClick({
                                //            menuPath: ['Modules', moduleName + '...']
                                //        });
                                //        win.elementWaitFor();
                                //    }
                                //}
                                
                                //Since the above does not work, these lines open the Loudness Module, unless it's open, then it closes
                                var moduleName = "Loudness";
                                sf.ui.izotope.menuClick({
                                    menuPath: ['Modules', moduleName + '...']
                                });
                                sf.wait({ intervalMs: 1500 });
                                
                                //This following section is supposed to click the Preset list and select my 'EBU_R128' preset, then Render it but here I have mixed things upp between scripts
                                function selectModuleLoudnessPreset(name) {
                                    var btn = sf.ui.izotope.windows.whoseTitle.is('Loudness').first.groups.whoseDescription.is('EffectPanel Loudness').first.groups.whoseDescription.is('EffectPanel Loudness').first.groups.whoseDescription.is('EffectPanel Loudness Header Background').first.popupButtons.whoseTitle.is('Presets').first.elementClick();
                                   if (btn.value.invalidate().value == name) return;
                                    btn.elementClick();
                                    sf.keyboard.press({ keys: 'enter' });
                                    while (true) {
                                        sf.engine.checkForCancellation();
                                        if (btn.value.invalidate().value == name) break;
                                        sf.keyboard.press({ keys: 'down' });
                                    }
                                }
                                function processOpenModuleLoudness() {
                                    sf.ui.izotope.windows.whoseTitle.is('Loudness').first.groups.whoseDescription.is('EffectPanel Loudness').first.buttons.whoseDescription.is('Render').first.elementClick();
                                }
                                
                                function processModuleLoudness(name) {
                                    sf.ui.izotope.invalidate();
                                    sf.ui.izotope.appActivateMainWindow();
                                //    ensureModuleLoudnessIsOpen();
                                    selectModuleLoudnessPreset(name);
                                    processOpenModuleLoudness();
                                
                                processModuleLoudness('EBU_R128');}
                                

                                So, as you see I still don't know how to check for and select the Preset in question in the Loudness Module and then Render it.
                                The code I snatched from the working Send to RX and run a Module Chain Preset I have does not work.
                                Ideas are welcome

                                1. I worked some more on this now - this script works for me in iZotope RX 7 :)

                                  function getSelectedPathsInFinder() {
                                      var count = sf.appleScript.finder.selection.length;
                                      var result = [];
                                      for (var i = 0; i < count; i++) {
                                          result.push(decodeURIComponent(sf.appleScript.finder.selection.getItem(i).asItem.path));
                                      }
                                      return result;
                                  }
                                  
                                  function processLoudness(path) {
                                      var izotopeRx = "/Applications/iZotope RX 7 Audio Editor.app";
                                  
                                      function openFileInIzotope(path) {
                                          sf.system.exec({
                                              commandLine: 'open -a "' + izotopeRx + '" "' + path + '"'
                                          });
                                          sf.ui.izotope.appWaitForActive();
                                          sf.ui.izotope.windows.whoseTitle.isNullOrEmpty.first.elementWaitFor({ waitForNoElement: true });
                                      }
                                  
                                      function ensureModuleLoudnessIsOpen() {
                                          var win = sf.ui.izotope.windows.whoseTitle.is('Loudness').first;
                                          if (!win.exists) {
                                              sf.ui.izotope.menuClick({
                                                  menuPath: ['Modules', 'Loudness...']
                                              });
                                              win.elementWaitFor({ timeout: 10000 });
                                          }
                                      }
                                  
                                      function selectModuleLoudnessPreset(name) {
                                          var btn = sf.ui.izotope.windows.whoseTitle.is('Loudness').first.groups.whoseDescription.is('EffectPanel Loudness').first.groups.whoseDescription.is('EffectPanel Loudness').first.groups.whoseDescription.is('EffectPanel Loudness Header Background').first.popupButtons.whoseTitle.is('Presets').first;
                                          if (btn.value.invalidate().value == name) return;
                                          btn.elementClick();
                                          sf.keyboard.press({ keys: 'enter' });
                                          var triedNames = {};
                                          while (true) {
                                              sf.engine.checkForCancellation();
                                              var thisName = btn.value.invalidate().value;
                                              if (thisName == name) break;
                                              if (triedNames[thisName]) throw 'Could not find preset: ' + name; //circled once already
                                              triedNames[thisName] = true;
                                              sf.keyboard.press({ keys: 'down' });
                                          }
                                      }
                                      function processOpenModuleLoudness() {
                                          sf.ui.izotope.windows.whoseTitle.is('Loudness').first.groups.whoseDescription.is('EffectPanel Loudness').first.groups.whoseDescription.is('EffectPanel Loudness').first.groups.whoseDescription.is('EffectPanel Loudness Footer Background').first.buttons.whoseDescription.is('Apply').first.elementClick();
                                  
                                          sf.wait({ intervalMs: 1000 });
                                  
                                          while (true) {
                                              sf.engine.checkForCancellation();
                                              var progressWin = sf.ui.izotope.windows.filter(function (win) {
                                                  return win.groups.whoseDescription.is('Task Progress View').first.exists;
                                              })[0];
                                              if (!progressWin || !progressWin.exists)
                                                  break;
                                              sf.wait({ intervalMs: 200 });
                                          }
                                  
                                          sf.wait({ intervalMs: 200 });
                                      }
                                  
                                      function processModuleLoudness(name) {
                                          sf.ui.izotope.invalidate();
                                          sf.ui.izotope.appActivateMainWindow();
                                          ensureModuleLoudnessIsOpen();
                                          selectModuleLoudnessPreset(name);
                                          processOpenModuleLoudness();        
                                      }
                                  
                                      function fileSave() {
                                          sf.ui.izotope.getMenuItem('File', 'Save').elementClick();
                                      }
                                  
                                      function fileClose() {
                                          sf.ui.izotope.getMenuItem('File', 'Close File').elementClick();
                                      }
                                  
                                      function main() {
                                          openFileInIzotope(path);
                                          processModuleLoudness('EBU_R128');
                                          fileSave();
                                          fileClose();
                                      }
                                  
                                      main();
                                  }
                                  
                                  function main() {
                                      var paths = getSelectedPathsInFinder();
                                      for (var i = 0; i < paths.length; i++) {
                                          var path = paths[i];
                                          processLoudness(path);
                                      }
                                  }
                                  
                                  main();
                                  
                                  Reply1 LikeSolution
                                  1. JJohn Rammelt @John_Rammelt
                                      2019-10-07 12:32:46.417Z

                                      You solved the entire thing!
                                      THIS is a time-saver for me, super!

                                      1. In reply tochrscheuer:
                                        ZZach McNees @Zach_McNees
                                          2023-05-15 19:54:16.025Z

                                          Looking for something similar to this. Basically want to take selected audio files in finder, open them in iZotope RX 10 Audio Editor and then process each file with Mouth De-click and then Overwrite existing file.

                    2. J
                      In reply toJohn_Rammelt:
                      Jeremiah Moore @Jeremiah_Moore
                        2023-10-07 02:04:27.408Z

                        awesome... I easily modified this to open selected videofiles in FFWorks, for conversion.

                        Could be modified to work with any app, simply by modifying the line with the pathname for the app.

                        -jeremiah

                        function getSelectedPathsInFinder() {
                            var count = sf.appleScript.finder.selection.length;
                            var result = [];
                            for(var i=0; i<count; i++) {
                                result.push(decodeURIComponent(sf.appleScript.finder.selection.getItem(i).asItem.path));
                            }
                            return result;
                        }
                        
                        var paths = getSelectedPathsInFinder().map(function(p){ return '"' + p + '"'; }).join(" ");
                        var TargetApp = "/Applications/ff·Works.app";
                        
                        sf.system.exec({
                            commandLine: 'open -a "' + TargetApp + '" ' + paths + ''
                        });