How to save current view menu settings?
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.
samuel henriques @samuel_henriqueshello @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] });
Chris Shaw @Chris_Shaw2021-04-10 20:55:51.584ZThat's a pretty slick bit of code there. Kudos.
Chris Shaw @Chris_Shaw2021-04-10 21:27:35.033ZBut 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)
samuel henriques @samuel_henriquesThank you so much Chris, you might be right, let's see how does it work for Yujiro.
samuel henriques @samuel_henriquesWith 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.
samuel henriques @samuel_henriquesUPDATE: 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
Yujiro Yonetsu @Yujiro_YonetsuHello.
Thank you so much!
@samuel_henriques , @Chris_ShawI 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")
Yujiro Yonetsu @Yujiro_YonetsuIt would be useful to have a list like this, which lists scripts that could be parts of a script.
How about it?
@chrscheuer- In reply toYujiro_Yonetsu⬆:
samuel henriques @samuel_henriquescool, 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
samuel henriques @samuel_henriquesBTW, 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"))
Yujiro Yonetsu @Yujiro_YonetsuI see!
Thank you!
- In reply tosamuel_henriques⬆:TThomas Gloor @Thomas_Gloor
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?
samuel henriques @samuel_henriquesHello Thomas,
Just tried it with pro tools 2023.12 and looks ok.Could you send a video capture of it failing?
- TThomas Gloor @Thomas_Gloor
Hey @samuel_henriques
I also run PT 2023.12 on Ventura.
On my laptop (MBP M2 Max 14'').Here's the capture:
samuel henriques @samuel_henriquesThank you Thomas
If you are getting the error on line 50, my original code doesn't have any code on line 50.- TThomas Gloor @Thomas_Gloor
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"], }); } }
samuel henriques @samuel_henriquesI 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
samuel henriques @samuel_henriquesCould 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- In reply tosamuel_henriques⬆:TThomas Gloor @Thomas_Gloor
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?
samuel henriques @samuel_henriqueswitch SF version are you in, I can try it here as well
- TThomas Gloor @Thomas_Gloor
Im not in from of my rig now unfortunately.
But I’m pretty sure it is the latest version! - In reply tosamuel_henriques⬆:TThomas Gloor @Thomas_Gloor
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....