function OnInit(initData) { initData.name = 'ViewerAutoOpenClose'; initData.version = '1.3'; initData.copyright = 'ViewerAutoOpenClose'; initData.url = 'https://resource.dopus.com/t/can-i-make-the-viewer-panel-open-close-when-a-media-file-is-selected-deselected/42698/11)'; initData.desc = 'ViewerAutoOpenClose'; initData.default_enable = true; initData.min_version = '12.0'; //Modified : 2022-11-14 } function OnAddCommands(addCmdData) { var cmd = addCmdData.AddCommand(); cmd.name = 'ViewerAutoOpenClose'; cmd.method = 'OnViewerAutoOpenClose'; cmd.desc = 'ViewerAutoOpenClose'; cmd.label = 'ViewerAutoOpenClose'; cmd.template = ''; cmd.hide = false; cmd.icon = 'script'; } function OnViewerAutoOpenClose(scriptCmdData) { var cmd = scriptCmdData.func.command; var tab = scriptCmdData.func.sourcetab; var dlg = scriptCmdData.func.Dlg(); if(!DOpus.Vars.Exists("ViewerAutoOpenClose")) //(if the variable does not exist, then) { DOpus.Vars.Set("ViewerAutoOpenClose") = 1; //Set the variable //if(DOpus.listers.lastactive.viewpane == 0) {cmd.RunCommand("Set VIEWPANE=on");} //Open if the viewer pane is closed } else { //Else, if the variable exists, then DOpus.Vars.Delete("ViewerAutoOpenClose"); //Delete variable to end the script, end the script for other instances DOpus.Delay(500); DOpus.Vars.Set("ViewerAutoOpenClose") = 1; //Set the variable //if(DOpus.listers.lastactive.viewpane == 1) {cmd.RunCommand("Set VIEWPANE=off");} //Close if the viewer is open } dlg.detach = true; dlg.template = "dialog1"; dlg.title = "OnSelect"; dlg.create(); dlg.show(); dlg.watchtab(tab, "select"); var msg; do { msg = dlg.GetMsg(); if(!DOpus.Vars.Exists("ViewerAutoOpenClose")) //If the variable does not exist, then { if(DOpus.listers.lastactive.viewpane == 1) {cmd.RunCommand("Set VIEWPANE=off");} //If the viewer pane is open, close the viewer pane break; //End the script } if (!msg.result) break; var event = msg.event; //Get event //var control = msg.control; var value = msg.value; //Log("Event: " + event + ", Control: " + control + ", Value: " + value); if(event == "tab" && value == "select") //If there is a selection event { tab.Update(); //Update if(tab.selstats.selfiles > 0) //If the selected file > 0 { var item = tab.selected_files(0); //Get the first file selected if(item.metadata == "image" || item.metadata == "video") //If it is an image or video, then { if(DOpus.listers.lastactive.viewpane == 0) //Open if the viewer pane is closed { cmd.RunCommand("Set VIEWPANE=on"); } } else {cmd.RunCommand("Set VIEWPANE=off");} //If it is not an image or video, close the viewer panel } else if(tab.selstats.selfiles == 0 && DOpus.listers.lastactive.viewpane == 1 || msg == 0) //Closes the viewer panel if no file is selected and the viewer pane is open { cmd.RunCommand("Set VIEWPANE=off"); } } } while(msg); /* function Log(msg, e) { DOpus.output(String(msg), e || false); } */ } // Called when a tab is activated function OnActivateTab(activateTabData) { var cmd = DOpus.Create().Command(); cmd.RunCommand("ViewerAutoOpenClose"); } // Called after a new folder is read in a tab function OnAfterFolderChange(afterFolderChangeData) { var cmd = DOpus.Create().Command(); cmd.RunCommand("ViewerAutoOpenClose"); } // Called when a tab is clicked with a qualifier key held down function OnTabClick(tabClickData) { var cmd = DOpus.Create().Command(); cmd.RunCommand("ViewerAutoOpenClose"); } // Called before a new folder is read in a tab function OnBeforeFolderChange(beforeFolderChange) { DOpus.Vars.Delete("ViewerAutoOpenClose"); } ==SCRIPT RESOURCES