Script Menu Side Effect?

I wrote a system wide hotkey script to pop up a check list of open listers so I can click the one I want to bring to the foreground. The way it behaves is best described by example.

My starting point is two open listers A and B. I press the hotkey to run the script and click/check B on the pop up menu. This correctly brings lister B to the foreground - so far so good. When I press the hotkey a second time, the menu pops up and at the same time lister A jumps to the foreground. This happens immediately - i.e. before I have made a selection from the menu. If I select B from the menu then lister B replaces lister A in the foreground. Next time I press the hotkey, lister A jumps back in front.

Script code as follows. Tested with vanilla (except for the hotkey) Opus 11.8 on Windows 7 64-bit.

Regards, AB

[code]@language vbscript
Option Explicit

Function OnClick(ByRef ClickData) ' This is the executable code
Dim cdf, cmd, dlg, i, list, menu, s
Set list = DOpus.NewVector : Set menu = DOpus.NewVector
Set cdf = ClickData.Func : Set cmd = cdf.Command : Set dlg = cdf.Dlg

cmd.deselect = False
If DOpus.listers.count = 1 Then
s = DOpus.listers(0).title
For i = 0 To DOpus.listers.count - 1
list(i) = DOpus.listers(i).title
DOpus.output "Listers(" & i & ") = " & list(i)
If i = 0 Then
menu(i) = 3
menu(i) = 0
End If
With dlg
.choices = list
.menu = menu
i = dlg.result
End With
DOpus.output " returned a value of " & i
If i > 0 Then s = list(i-1) Else s = ""
End If
If Not s = "" Then
s = "Go FINDTITLE " & """" & s & """"
DOpus.output s
cmd.runcommand s
End If
End Function[/code]

If you don't tell dlg which window to use as its parent, it has to pick one arbitrarily. That window will come to the front so that the menu can also be shown.

Thanks. Changing Set dlg = cdf.Dlg to Set dlg = DOpus.Dlg does the trick.

Regards, AB