No internet connection
  1. Home
  2. How to

Stop script upon cancel....how?

By AL L @AL_L
    2022-06-29 09:35:11.167Z2022-06-29 13:37:23.934Z

    Hello,

    I have the following script to import an AAF, but would like the option for the script to be aborted when I cancel out of this first "open file" window..:

    When I manually cancel this window (either with esc-key or by clicking "cancel"), the script keeps continuing, and I don't want that.

    How do I do that?
    Here's the script:

    sf.ui.proTools.appActivate();
    
    sf.ui.proTools.appWaitForActive();
    
    
    sf.ui.proTools.mainWindow.counterDisplay.textFields.whoseTitle.is("Main Counter").first.elementClick();
    sf.keyboard.press({ keys: "cmd+c, return", });
    
    
    
    
    sf.ui.proTools.menuClick({ menuPath: ['File', 'Import', 'Session Data...'] });
    
    sf.ui.proTools.windows.whoseTitle.is("Open").first.getElement("AXDefaultButton").elementWaitFor({
        onCancel: "Abort",
        onError: "Continue",
    });
    var dlg = sf.ui.proTools.dialogWaitForManual({
        dialogTitle: 'Import Session Data',
        timeout: -1
    }).dialog;
    
    
    var popupBtn = dlg.groups.getByTitle('Media Options').popupButtons.allItems[1];
    popupBtn.popupMenuSelect({
        menuPath: ['Copy from source media']
    });
    

    Thanks!

    Solved in post #2, click to view
    • 2 replies
    1. Chris Shaw @Chris_Shaw2022-06-29 17:08:07.381Z2022-06-29 17:55:44.187Z

      Hey AL_L,

      As far as I know there's no way for SF to know which button has been clicked in the Open File dialog but we can tell when windows and dialogs appear and disappear so we can use that info to get the results you want.

      The key here is to wait and see if the Import Session Data window appears after the Open File dialog disappears. If it doesn't then the user must have clicked cancel in the Open File dialog:

      sf.ui.proTools.appActivate();
      
      sf.ui.proTools.appWaitForActive();
      
      
      sf.ui.proTools.mainWindow.counterDisplay.textFields.whoseTitle.is("Main Counter").first.elementClick();
      sf.keyboard.press({ keys: "cmd+c, return", });
      
      sf.ui.proTools.menuClick({ menuPath: ['File', 'Import', 'Session Data...'] });
      
      //Wait for Open Session window to appear
      sf.ui.proTools.windows.whoseTitle.is("Open").first.elementWaitFor({
      });
      
      // Wait for open session window to disappear
      sf.ui.proTools.windows.whoseTitle.is("Open").first.elementWaitFor({
          waitType: "Disappear",
          timeout: -1
      });
      
      // Now that the open files window is gone
      // Briefly wait for any confirmation dialogs that may appear before Import Track Data window (If the user clicked "Open")
      // (ex: "Session Start Time is different" )
      const confWin = sf.ui.proTools.confirmationDialog
      const isThereAConfWin = confWin.elementWaitFor({
          timeout: 500,
          onError: "Continue"
      }).success
      
      // If there is a confirmation window, wait for the user to dismiss it
      if (isThereAConfWin){
          confWin.elementWaitFor({waitType:"Disappear",timeout:-1})
      }
      
      // Now let's wait for the Import Session Data window to appear. If it doesn't then user must have canceled
      // We'll store the results by using the `.success` property
      const didImportWindowAppear = sf.ui.proTools.windows.whoseTitle.is("Import Session Data").first.elementWaitFor({
          timeout: 500,
          pollingInterval: 100,
          onError: "Continue"
      }).success //success will return true or false
      
      //If Import Session Data window did not appear, stop the script
      if (!didImportWindowAppear) {
          sf.interaction.notify({
              title: "User Canceled"
          });
          throw 0
      }
      
      // If we're here the then the Import Session Data window must be open. 
      // Continue on -
      var dlg = sf.ui.proTools.dialogWaitForManual({
           dialogTitle: 'Import Session Data',
           timeout: -1
       }).dialog;
      
      
      var popupBtn = dlg.groups.getByTitle('Media Options').popupButtons.allItems[1];
      popupBtn.popupMenuSelect({
          menuPath: ['Copy from source media']
      });
      
      Reply1 LikeSolution
      1. A
        In reply toAL_L:
        AL L @AL_L
          2022-06-29 19:16:59.476Z

          @Chris_Shaw Thanks so much ! That worked perfectly...