GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Scripts (JS & VBS) Snippet: Enumerating listers and tabs


The scripting API returns collections of objects in various places. For example, DOpus.listers is a collection containing a lister object for each lister that is open.

This post provides examples of how to enumerate those collections in JScript and VBScript.

The two scripts below do the same thing: Print the path of each folder tab in each lister. The only difference between the scripts is the language they are written in.


DOpus.Output("These tabs are open:");
for (var eListers = new Enumerator(DOpus.listers); !eListers.atEnd(); eListers.moveNext())
	for (var eTabs = new Enumerator(eListers.item().tabs); !eTabs.atEnd(); eTabs.moveNext())
		DOpus.Output("  " + eTabs.item().path);


Option Explicit
Dim lister
Dim tab
DOpus.Output "These tabs are open:"
DOpus.Output ""
For Each lister In DOpus.listers
	For Each tab In lister.tabs
		DOpus.Output "  " & tab.path

Removing objects while they are being enumerated:

To avoid unexpected behaviour in your scripts, be careful not to remove objects from the collection(s) you are enumerating.

For example, if you wish to go through each lister or tab and close particular ones, you should make a note of all the objects you wish to close, and finish enumerating, before you start closing them.

One way to do this is to create your own Vector and store the objects you wish to close in it. (It's safe to enumerate a Vector you created yourself in this way, unlike the collections which Opus gives to you.) [In some cases, this requires Directory Opus 11.3 beta 1 or above to work.]

For a real example of this, see this script: Close all tabs matching a path wildcard.

Active a tab via scripting?
DOpusRT /info paths: no special folders
Close lister if lister is open