No internet connection
  1. Home
  2. How to

How to save current view menu settings?

By Yujiro Yonetsu @Yujiro_Yonetsu
    2021-04-10 16:21:24.990Z

    Hello.

    I want to memory "Edit Window Views" current state and then revert back to the original state after I do the script.
    Some of the scripts need to show the IO view, and I want to return to the original state after they are done.

    For example, something similar to this, how to go back to the start window of the script is what I was taught in this forum.

    //memory original window
    let originalWin = sf.ui.proTools.focusedWindow.title.value.split(":").slice(0, 1).join(":")
    
    
    /////Do Something Script///////
    ////Scripts that require I to navigate to an edit window, for example////
    
    
    //show original window
    sf.ui.proTools.menuClick({ menuPath: ["Window", originalWin] });
    

    I want to create an Edit window View case for this kind of thing.

    Please help me.

    • 22 replies

    There are 22 replies. Estimated reading time: 17 minutes

    1. samuel henriques @samuel_henriques
        2021-04-10 19:52:48.315Z2021-04-12 21:53:44.909Z

        hello @Yujiro_Yonetsu,

        try this.

        would you change the title of the question to "How to save current view menu settings?" just so it's easier to search in the future, please.

        It doesn't look like a lot of code, but took me a few hours to figure some very specific javascript bits. So try it and let me know please.

        /**
         * @param {array} path - menu full path
         * @param {'Enable'|'Disable'} targetValue
         */
        function menuClick(path, targetValue) {
            sf.ui.proTools.menuClick({ menuPath: path, targetValue: targetValue });
        }
        
        /**
         * @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
        }
        
        
        sf.ui.proTools.appActivateMainWindow()
        
        //memory original focused window
        let originalWin = sf.ui.proTools.focusedWindow.title.value.split(":").slice(0, 1).join(":")
        
        let viewMenu = getMenuItems("View")
        //let OptionsMenu = getMenuItems("Options")
        let windowMenu = getMenuItems("Window")
        
        
        
        
        //  Your code here
        
        
        
        ///  View Menu Back to original
        viewMenu.menuAllEnabled.forEach(x => menuClick(x, "Enable"))
        viewMenu.menuAllDisabled.forEach(x => menuClick(x, "Disable"))
        
        ///  Window Menu Back to original
        windowMenu.menuAllEnabled.forEach(x => menuClick(x, "Enable"))
        windowMenu.menuAllDisabled.forEach(x => menuClick(x, "Disable"))
        
        //focus original window
        sf.ui.proTools.menuClick({ menuPath: ["Window", originalWin] });
        
        1. That's a pretty slick bit of code there. Kudos.

          1. But I think Yujiro wants to store and recall the memory locations window too.

            This seems to work (probably needs a bit of testing / debugging).
            I just reused your Get Path code:

            function menuClick(path) {
                sf.ui.proTools.menuClick({ menuPath: path, looseMatch: true, targetValue: "Enable" });
            }
            
            sf.ui.proTools.appActivateMainWindow();
            
            
            //  Get path of current enabled items from view menu
            let viewState = sf.ui.proTools.getMenuItem("View").popupMenuFetchAllItems().menuItems.filter(x =>
                x.element.isMenuChecked).map(x => ["View"].concat(x.path.slice()));
            sf.ui.proTools.appActivateMainWindow();
            
            //  Get path of current enabled items from view menu
            let viewWindows = sf.ui.proTools.getMenuItem("Window").popupMenuFetchAllItems().menuItems.filter(x =>
                x.element.isMenuChecked).map(x => ["Window"].concat(x.path.slice()));
            sf.ui.proTools.appActivateMainWindow();
            
            
            
            ///  Your code here
            
            
            
            ///  Back to original
            viewState.forEach(menuClick);
            viewWindows.forEach(menuClick)
            
            1. samuel henriques @samuel_henriques
                2021-04-10 21:41:51.173Z

                Thank you so much Chris, you might be right, let's see how does it work for Yujiro.

                1. samuel henriques @samuel_henriques
                    2021-04-11 09:11:02.795Z

                    With all the excitement I completely forgot about the disabled items, those need to be remembered also. :))

                    Just updated above. It works for the view and options menu,
                    Either this new code or the previous, don't work for the window menu, I have the feeling the "-" is not enabled, but something else. I'll try to work on it today, but I'm not sure if I can.

                    Anyway, pretty happy about how this is working out, I hope it is useful.

                    1. samuel henriques @samuel_henriques
                        2021-04-11 16:15:31.135Z

                        UPDATE: thanks to @Kitch and @Dustin_Harris, I managed to add the window menu.
                        I think it need a bit of testing but this should do it.

                        Thank you

                        1. Yujiro Yonetsu @Yujiro_Yonetsu
                            2021-04-12 21:13:56.232Z

                            Hello.

                            Thank you so much!
                            @samuel_henriques , @Chris_Shaw

                            I can't understand it......, But I think this is a very useful script.
                            I haven't figured out how it works, but it seems like it could be incorporated into various scripts to make them more versatile!

                            When I actually tested it, it worked perfectly for the "View",
                            but it did not work correctly for "Window".
                            (started in "Mix", but ended in "Edit")

                            1. Yujiro Yonetsu @Yujiro_Yonetsu
                                2021-04-12 21:14:21.112Z

                                It would be useful to have a list like this, which lists scripts that could be parts of a script.
                                How about it?
                                @chrscheuer

                                1. In reply toYujiro_Yonetsu:
                                  samuel henriques @samuel_henriques
                                    2021-04-12 21:52:17.371Z

                                    cool, it looks correct.

                                    if you are using it with the "Window" menu, it wont make you end on the initial selected window, But it will set the state enable or disable as they were before the script.

                                    if you want to return to the edit / mix window, you can use the code as you wrote on your question.

                                    I added it to the code I posted

                                    1. samuel henriques @samuel_henriques
                                        2021-04-12 22:24:42.222Z

                                        BTW, you don't need to get and set the "Window" menu, if you code is not going to change it. you can remove the lines:

                                        //let OptionsMenu = getMenuItems("Options")
                                        let windowMenu = getMenuItems("Window")
                                        

                                        and:

                                        ///  Window Menu Back to original
                                        windowMenu.menuAllEnabled.forEach(x => menuClick(x, "Enable"))
                                        windowMenu.menuAllDisabled.forEach(x => menuClick(x, "Disable"))
                                        
                                        1. Yujiro Yonetsu @Yujiro_Yonetsu
                                            2021-04-13 14:20:21.962Z

                                            I see!

                                            Thank you!

                            2. TThomas Gloor @Thomas_Gloor
                                2024-02-27 21:59:21.628Z

                                Hey @samuel_henriques

                                I've been using this for two weeks without any problems, and it stopped working. I tried to add press esc or left. But it get's stuck on the menu and fails.

                                Any idea?

                                1. samuel henriques @samuel_henriques
                                    2024-02-28 00:31:18.000Z

                                    Hello Thomas,
                                    Just tried it with pro tools 2023.12 and looks ok.

                                    Could you send a video capture of it failing?

                                    1. TThomas Gloor @Thomas_Gloor
                                        2024-02-28 08:06:39.393Z
                                        1. samuel henriques @samuel_henriques
                                            2024-02-28 11:03:38.884Z2024-02-28 11:57:27.894Z

                                            Thank you Thomas
                                            If you are getting the error on line 50, my original code doesn't have any code on line 50.

                                            1. TThomas Gloor @Thomas_Gloor
                                                2024-02-28 11:42:05.654Z

                                                Hey @samuel_henriques ,

                                                I did use your function in a different script (see below). I tried to copy paste the one you just posted, and it get's stuck the same way...
                                                Could it be a system problem?

                                                Here's the code I use. It gets stuck at line 46, when trying to get the menu items.

                                                // Store Pro Tools Options
                                                // Version 1.0.0
                                                
                                                const pt = sf.ui.proTools
                                                const hasAlt = event.keyboardState.hasAlt
                                                const hasCmd = event.keyboardState.hasCommand
                                                const hasCtrl = event.keyboardState.hasControl
                                                const hasShift = event.keyboardState.hasShift
                                                
                                                pt.appActivateMainWindow();
                                                pt.mainWindow.invalidate();
                                                
                                                /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                ////////////////////////////////////////CONST / VARIABLES / USER DEFINED/////////////////////////////////////
                                                /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                
                                                let dataSavePath = "My save path"
                                                
                                                //////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                ///////////////////////////////////////////////////MAIN SCRIPT////////////////////////////////////////////////
                                                //////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                
                                                // Get settings from dropdown menu
                                                let viewMenuSettings = getMenuItems("View")
                                                let optionsMenuSettings = getMenuItems("Options");
                                                
                                                let proToolsMenuSettings = { optionsMenuSettings, viewMenuSettings }
                                                
                                                writeRecallDataToJson({
                                                    jsonDestination: dataSavePath,
                                                    dataObject: proToolsMenuSettings,
                                                    jsonFileName: "TGMix Pro Tools Settings.json"
                                                })
                                                
                                                log("Pro Tools Session Options Stored")
                                                
                                                /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                //////////////////////////////////////////////////FUNCTIONS//////////////////////////////////////////////////
                                                /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                
                                                ////////////////////////////////////////////////// GET MENU ITEMS
                                                /** @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
                                                };
                                                
                                                
                                                //////////////////////////////////////////////////WRITE DATA TO JSON
                                                function writeRecallDataToJson({ jsonDestination, dataObject, jsonFileName }) {
                                                    //save settings (goes in the script that saves the settings)
                                                
                                                    let writeToJSON = sf.file.writeJson({
                                                        path: jsonDestination + "/" + jsonFileName,
                                                        json: dataObject
                                                    }).success;
                                                
                                                    if (!writeToJSON) { alert("Error saving settings") } else { log("Settings successfully save to session folder") }
                                                
                                                }
                                                
                                                //////////////////////////////////////////////////MAIN WINDOW STATUS
                                                function mainWindowStatus() {
                                                    if (sf.ui.proTools.getMenuItem('Window', 'Mix').isMenuChecked) {
                                                        sf.ui.proTools.menuClick({
                                                            menuPath: ["Window", "Edit"],
                                                        });
                                                        return "Mix";
                                                    } else {
                                                        return "Edit";
                                                    }
                                                }
                                                
                                                //////////////////////////////////////////////////RETURN TO STARTING MAIN WINDOW
                                                function returnToStartingMainWIndow(mainWindow) {
                                                    if (mainWindow == "Mix") {
                                                        sf.ui.proTools.menuClick({
                                                            menuPath: ["Window", "Mix"],
                                                        });
                                                    }
                                                }
                                                
                                                
                                                
                                                1. samuel henriques @samuel_henriques
                                                    2024-02-28 11:59:29.457Z

                                                    I deleted the code I posted so the thread doesn't get so confusing.
                                                    The code you posted works for me. Including writing the json to disk

                                                    1. samuel henriques @samuel_henriques
                                                        2024-02-28 12:07:59.772Z

                                                        Could it be the pro tools personality?
                                                        If you are having this for a few days, I recon you've quit pro tools and probably restated computer a few times.
                                                        Could you try parts of the code to see where the mistake could be,
                                                        let menuItems = sf.ui.proTools.getMenuItem("View").popupMenuFetchAllItems().menuItems
                                                        and log menuItems to see if you get it

                                                        1. TThomas Gloor @Thomas_Gloor
                                                            2024-02-28 12:08:22.557Z

                                                            Ok…That’s super weird.
                                                            It’s stays stuck when opening the menu, not Matter which one.

                                                            Do you know of any OSX preferences that could be messing with it?

                                                            1. samuel henriques @samuel_henriques
                                                                2024-02-28 12:12:54.097Z

                                                                witch SF version are you in, I can try it here as well

                                                                1. TThomas Gloor @Thomas_Gloor
                                                                    2024-02-28 12:18:57.269Z

                                                                    Im not in from of my rig now unfortunately.
                                                                    But I’m pretty sure it is the latest version!

                                                                    1. TThomas Gloor @Thomas_Gloor
                                                                        2024-03-01 08:13:33.406Z2024-03-01 09:39:12.615Z

                                                                        Hey @samuel_henriques
                                                                        I am now back at the studio and my laptop is hooked to a screen which is bigger than my laptop screen.
                                                                        It works fine again.

                                                                        What seems weird, is that I wrote the code incoroporating your function on my laptop....