No internet connection
  1. Home
  2. How to

Get menu items. I'm pretty sure it's super easy, but I can't wrap my head around it.

By Thomas Gloor @Thomas_Gloor
    2024-02-02 18:40:39.524Z

    Hi everyone,

    Silly question, but I really can't figure it out...

    Is there a way to fetch all menu items from the top menus like "Options" or "Setup"?

    I'd like to write a script that stores and resets my OPTIONS, not only my preferences.

    Ideally, I'd like to map the menu items, and check if they are enabled or not, to build an options object.

    Thank you in advance!

    • 6 replies
    1. Here's a great script from @samuel_henriques from a while back that will do this:

      sf.ui.proTools.appActivate();
      /**
       * @param {String} menuName - Menu Name
       */
      function getMenuItems(menuName) {
          //  Get path of current enabled && disabled items from menu
          let menuItems = sf.ui.proTools.getMenuItem(menuName).popupMenuFetchAllItems().menuItems
          let menuEnabled = menuItems.filter(x =>
              x.element.isMenuChecked ||
              x.element.getString('AXMenuItemMarkChar') === ('-')).map(x => [menuName].concat(x.path.slice()))
          let menuDisabled = menuItems.filter(x =>
              !x.element.isMenuChecked &&
              x.element.getString('AXMenuItemMarkChar') !== ('-')).map(x => [menuName].concat(x.path.slice()))
          sf.ui.proTools.appActivateMainWindow()
      
          let menu = {
              menuAllEnabled: menuEnabled,
              menuAllDisabled: menuDisabled
          }
          return menu
      };
      
      // Get settings from dropdown menu
      let menuSettings = getMenuItems("Options");
      
      
      // Do something here
      sf.interaction.displayDialog({prompt: `Change some settings in options menu.
      The script will then restore settings after clicking OK`,title:"Change Things"});
      
      
      //Restore settings
      
      //      Select menu items
      menuSettings.menuAllEnabled.forEach(x=> {
          sf.ui.proTools.menuClick({menuPath:x,targetValue:'Enable'})
      });
      
      //      Deselect menu items
      menuSettings.menuAllDisabled.forEach(x=> {
          sf.ui.proTools.menuClick({menuPath:x,targetValue:'Disable'})
      });
      
      1. TThomas Gloor @Thomas_Gloor
          2024-02-03 08:34:51.392Z2024-02-03 09:19:25.199Z

          Hey @Chris_Shaw

          Thank you lots!

          I modified it so it writes the settings to a JSON file to recall later. Works great!

          By any chance, do you know if it is possible to quickly map all checkboxes and radio buttons of a tab in the preference window?

          1. Have you checked out the PT Preference Manager app by @chrscheuer in the store?

            1. TThomas Gloor @Thomas_Gloor
                2024-02-03 18:17:39.842Z

                Hey @Chris_Shaw

                Thank you for answering. Yes I do but I’d like to learn how to do it and apply it in a bigger script!

                1. This will grab / set the check box setting in the Editing prefs pane

                  const prefPaneName = "Editing"
                  
                  //Ensure Pref window is open
                  let prefsWindow = sf.ui.proTools.windows.whoseTitle.is("Pro Tools Preferences").first
                  if (!prefsWindow.exists) {
                      sf.ui.proTools.menuClick({ menuPath: ["Setup", "Preferences..."] })
                      prefsWindow.elementWaitFor()
                  }
                  
                  //Open Editing Tab
                  let prefsTab = prefsWindow.radioButtons.whoseTitle.contains(prefPaneName).first
                  prefsTab.elementClick();
                  
                  //Get pane checkbox Settings
                  let prefPaneGroups = prefsWindow.groups.allItems
                  let prefsTabSettings = {}
                  
                  prefPaneGroups.forEach(group => {
                      let tempObject = {}
                  
                      group.checkBoxes.map(cb => {
                          tempObject[cb.title.value] = cb.isCheckBoxChecked
                      })
                      prefsTabSettings[group.title.value] = tempObject
                  })
                  
                  // Save prefsTabSettings as JSON here
                  
                  sf.interaction.displayDialog({ prompt: "Change some settings. After clicking OK script will reset them" })
                  
                  
                  
                  
                  //Reset Pref Tab settings
                  //(Put code here for loading JSON, opening prefs, and selecting tab (as above) )
                  for (const group in prefsTabSettings) {
                  
                      for (const cb in prefsTabSettings[group]) {
                  
                          let checkBoxGroup = prefsWindow.groups.whoseTitle.is(group).first;
                          const checkBoxToSet = checkBoxGroup.checkBoxes.whoseTitle.is(cb).first;
                        
                          // @type {"Enable" | "Disable"}
                          const targetValue = prefsTabSettings[group][cb] ? "Enable" : "Disable"
                  
                          checkBoxToSet.checkboxSet({targetValue})
                      }
                  }
                  
                  
                  
            2. In reply toChris_Shaw:
              TThomas Gloor @Thomas_Gloor
                2024-02-27 19:44:46.829Z

                Hey @Chris_Shaw
                I can't understand, but This stopped working from a day to another. It get's stuck with the menu open.
                I tried dismissing the menu, typing esc or left. Nothing works.

                Do you have an Idea? Thank you in advance