/* =================================================================================================== AUTHOR : Ken Function : Automatically read ADS tag and set to variable when item is clicked (AutoOpenClose) Created : 2022-12-11 Modified : 2023-01-05 Version : v1.1.2 =================================================================================================== */ // EventUpdateVar-ADS (AutoOpenClose) // (c) 2022 Ken // This is a script for Directory Opus. // See https://www.gpsoft.com.au/DScripts/redirect.asp?page=scripts for development information. // Called by Directory Opus to initialize the script function OnInit(initData) { initData.name = "EventUpdateVar-ADS (AutoOpenClose)"; initData.version = "1.1.2"; initData.copyright = "(c) 2022 Ken"; initData.url = "https://resource.dopus.com/t/set-tags-add-tags-by-list-beta/43269/2"; initData.desc = "Display ADS in the Status Bar. \r\nFor Preferences / Display / Status Bar: ADS={var:tab:ADS}"; initData.default_enable = true; initData.min_version = "12.0"; } function OnAddCommands(addCmdData) { var cmd = addCmdData.AddCommand(); cmd.name = "UpdateVarADS"; cmd.method = "OnUpdateVarADS"; cmd.desc = "EventUpdateVar-ADS"; cmd.label = "UpdateVarADS"; cmd.template = ""; cmd.hide = false; cmd.icon = 'script'; } function OnUpdateVarADS(scriptCmdData) { var dlg = scriptCmdData.func.Dlg(); var tab = scriptCmdData.func.sourcetab; var cmd = scriptCmdData.func.command; if (!tab) return; if (!DOpus.Vars.Exists("UpdateVarADS")) // Sets the variable if it does not exist { DOpus.Vars.Set("UpdateVarADS") = 1; } dlg.detach = true; dlg.template = "dialog1"; dlg.title = "OnSelect"; dlg.create(); //dlg.show(); dlg.opacity = 0; // Make the dialog invisible dlg.watchtab(tab, "select"); var msg; do { if (DOpus.Vars.Exists("UpdateVarADS")) // If the variable exists, close duplicate dialog { DOpus.Vars.Delete("UpdateVarADS"); var randomNum = Math.floor(Math.random() * 10); if (randomNum) {DOpus.Delay(randomNum)} DOpus.Vars.Set("UpdateVarADS") = 1; } else { // If the variable does not exist, refresh and exit cmd.UpdateToggle(); // Refresh break; // Exit } msg = dlg.GetMsg(); var msgResult = msg.result; if (!msgResult) break; var event = msg.event; //var control = msg.control; var value = msg.value; //DOpus.Output("Event: " + event + ", Value: " + value); if (event == "tab" && value == "select") // If there is a select event { tab.Update(); if (tab.Selected.count > 0) { tab.vars.Delete("ADS"); var fsu = DOpus.fsutil; var ADSfile = tab.Selected(0).realpath + ":Tags"; // ADSfile // If ADSfile exists if (fsu.Exists(ADSfile)) { var ST = DOpus.Create.StringTools(); var openText = fsu.OpenFile(ADSfile, "r"); // Read ADSfile var text = openText.Read(); openText.Close; var textbom = ST.Decode(text, "utf-8 bom"); // Decode as UTF-8 with BOM var myArray = textbom.split("\r\n"); // The separator is \r\n var ADS = myArray[0]; // Get the first line } else {var ADS = "";} tab.vars.Set('ADS', ADS); } else { tab.vars.Set('ADS') = ""; } cmd.UpdateToggle(); // Refresh } else if (value == "close") break } while (msg); // msg loop } var cmd = DOpus.Create().Command(); // Called when a new tab is opened function OnOpenTab(openTabData) { cmd.RunCommand('UpdateVarADS') } // Called when the source and destination are changed function OnSourceDestChange(sourceDestChangeData) { if (!DOpus.Vars.Exists("sourceDestChanged")) { DOpus.Vars.Set("sourceDestChanged") = 1 cmd.RunCommand('UpdateVarADS') } else { DOpus.Delay(200); DOpus.Vars.Delete("sourceDestChanged"); return } } /* For Preferences / Display / Status Bar: ADS={var:tab:ADS} */ ==SCRIPT RESOURCES