OnOpenLister Behaviour II

My test case is an almost completely vanilla DO12 configuration with a single active OnOpenLister event script, courtesy of Leo from a couple of years ago.

[code]Option Explicit

Function OnInit(initData)
initData.name = "Set Lister Title"
initData.desc = "Customise lister title bars"
initData.copyright = "(C) 2014 Leo Davidson (original code)"
initData.version = "1.0"
initData.default_enable = true
End Function

' Called when a new lister is opened
Function OnOpenLister(ByRef OpenListerData)

Dim s, cmd
Dim objWSH, objEnv

'If OpenListerData.lister.custom_title = "" Then
Set objWSH = CreateObject("WScript.Shell")
Set objEnv = objWSH.Environment("Process")
If OpenListerData.lister.layout = "" Then
s = objEnv("USERNAME") & " on " & objEnv("USERDOMAIN")
Else
s = "Layout " & OpenListerData.lister.layout & " on " & objEnv("USERDOMAIN")
End If
Set cmd = DOpus.NewCommand
cmd.SetSourceTab openListerData.lister.activetab
cmd.RunCommand "Set LISTERTITLE=""DOpus " & DOpus.version.product & " - " & s & " - %P"""
'End If

End Function[/code]
I start with a single lister as shown immediately below. This is the current (default) lister and it has no custom lister title. So far so good, everything looks OK.


Now I close the (only) lister and open a new one via right mouse click on the Opus system tray icon and Open New Lister. The custom lister title is as expected, everything still looks OK.


Now I close the (only) lister again and open a new one via right mouse click on the Opus system tray icon and Open New Lister. The custom lister title has gone! If I repeat the process, every alternate new lister has the custom title and every other lister does not.


The same alternating behaviour can be demonstrated by a sequence of Go NEW commands or opening and closing new listers by means of Win+E.

I won't complicate matters here, but I subsequently tried another approach to reliably setting a custom lister title by using a combination of OnActivateTab, OnBeforeFolderChange and OnAfterFolderChange events. The results from that are harder to describe but were even funkier. When time permits I'll create a separate report.

Regards, AB

Is the script always being run when you expect it to be? Is the script failing sometimes and producing errors in the script log? Is it being run but not getting the values it expects?

You can find all those out by adding some DOpus.Output calls into the script to debug it, and the answers will tell us which direction to look in an whether it is the script itself that is wrong, or something Opus is doing, or a config problem or clash with another script that's also running on your setup.

I have simplified the test script and added DOpus.output statements to track what's going on.

function OnInit(d)
{
	d.name = "Event_Lister_Title";
	d.default_enable = true;
	var objWSH =  new ActiveXObject("WScript.Shell");
	var objEnv = objWSH.Environment("Process");
	var me = objEnv("USERNAME") + " on " + objEnv("USERDOMAIN");
	DOpus.vars.set("ListerTitlePrefix",DOpus.version + " - [" + me + "] - ");
}

function OnOpenLister(d)
{
	var str = "INHERITED Custom Title is : " + d.lister.custom_title;
	DOpus.output(str);
	var objcmd = DOpus.create.command;
	objcmd.SetSourceTab(d.lister.activetab);
	var cmd = 'Set LISTERTITLE "' + DOpus.vars.get("ListerTitlePrefix") + '%P"';
	DOpus.output(cmd);
	objcmd.runcommand(cmd);
}

I start with a single lister and the only script that is active is the one listed above. I issue an immediate >Set LISTERTITLE= command to clear any custom title, then close the lister and exit Directory Opus via the context menu in the system tray. The "default" lister is thus set to the lister I just closed which has no custom title.


Now I open Directory Opus from the Start Menu. The "default" lister opens and the custom title is set correctly.


Now I close the lister and Open New Lister via the system tray context menu. The correct custom Set LISTERTITLE command is executed by the event handler but the result is that the custom title is cleared.


If I now repeat the last step, the custom title is created correctly every alternate time and cleared every other time. This is repeatable on my test system which is very close to a vanilla "as shipped" configuration.

Regards, AB

This is what you need:


Thanks Leo. As usual, it pays to read the manual carefully! All working now. Code as follows for anyone who is interested.

[code]function OnInit(d)
{
d.name = "Event_Lister_Title";
d.copyright = "AussieBoykie"
d.default_enable = true;
var objWSH = new ActiveXObject("WScript.Shell");
var objEnv = objWSH.Environment("Process");
DOpus.vars.set("ListerTitleUser",objEnv("USERNAME"));
DOpus.vars.set("ListerTitleDomain",objEnv("USERDOMAIN"));
var objcfg = d.config;
objcfg.debug = false;
}

function OnOpenLister(d)
{
var dbg = Script.config.debug;
var str = "INHERITED Custom Title is : " + d.lister.custom_title;
if (dbg) DOpus.output(str);
var str = DOpus.version + " - [";
if (d.lister.layout=="") str = str + DOpus.vars.get("ListerTitleUser");
else str = str + "Layout " + d.lister.layout;
str = str + " on " + DOpus.vars.get("ListerTitleDomain") + "] - %P";
var objcmd = DOpus.create.command;
objcmd.SetSourceTab(d.lister.activetab);
var cmd = 'Set LISTERTITLE "notoggle:' + str + '"';
if (dbg) DOpus.output(cmd);
objcmd.runcommand(cmd);
}[/code]
Regards, AB