/////////////////////////////////////////////////////////////////////////////// //Script Initialization Demonstration ////////////////////////////////////////////////////////////////////////////// //The first time DO pulls a script, right before calling OnInit(), the object //"Script" is not available yet. We can make use of that fact and detect wether //this Script is already fully initialized or not (OnInit() has been called). // //This is useful in cases where you need to access Script.config items to init //global objects for later use in events, script commands or columns. // //You can setup a script-global logging instance e.g., which can be prepared //with data and configurations out of Script.config. try { //Execution will fail on the next line if the script is currently reloaded //and initialized. The try-statement around here, allows to prevent an //exception and gracefully continue execution in the catch block below if (Script); //If we got here, the Script object exists and the scripting environment //is in fully working condition. DO is about to call an event, command or //column function. DOpus.Output("DO is about to call an event-function, script-command or column."); //Setup a global object here, which depends on Script.config items and //is used by any event, script command or column later on. var Goodbye = new CustomGoodbye( Script.config["Goodbye"] ); } catch(e){ //If execution reaches this point, the script was reloaded and OnInit() is //going to be called next. We're are past all possible parsing errors here. //DO is not going to call any event, command or column function yet. //The following lines will only be executed if script was reloaded or //dopus started up, a nice place to clear the script console e.g. DOpus.ClearOutput(); DOpus.Output("Script (re)loaded successfully, calling OnInit() next."); } DOpus.Output("You will always see this at DO-startup, script-reload or right before a function call."); /////////////////////////////////////////////////////////////////////////////// function OnInit(data) { data.name = "ScriptInitDemo"; data.desc = "Script Initialization demo."; data.default_enable = true; data.min_version = "11.4" data.config["Goodbye"] = "See you and thanks for watching! o)"; DOpus.Output("OnInit() called."); DOpus.Output("Now doubleclick a folder to fire doubleclick event and watch a different output."); } ////////////////////////////////////////////////////////////////////////////// function OnDoubleClick(data) { DOpus.Output("DoubleClick() event fired, accessing global object initialized with script settings."); DOpus.Output(Goodbye.text); } ////////////////////////////////////////////////////////////////////////////// function CustomGoodbye( textIn){ this.text = textIn; }