Set TREEROOT automatically

Is it possible to execute Set TREEROOT [folder] for every newly open lister, excluding situations where opened folder is outside [folder]?

My place where I have all my stuff is put deep in c:\users\username\documents which makes folder tree expand horizontally and I don't like it. I would like to limit folder tree to c:\users\username\documents\ (or something else) so the folder tree is more clear.

PS. I tried to use collections but they don't seem to be easy to handle as I can't use lib:/... path in every place (as opposed to real path).

Give this script a try:

AutoTreeRoot.vbs.txt (1.89 KB)

Below is all the code that's in the script. The .txt download has more code but it's all commented out and not used at the moment. Some of it might be useful if you want to trigger the tree-root change on other events, but I think what it has now will probably give you what you want.

[code]option explicit

Dim RootPath
RootPath = DOpus.FSUtil.Resolve("/mydocuments")

Function OnInit(initData)
initData.name = "AutoTreeRoot"
initData.desc = "Automatically set the tree root to a folder in new windows"
initData.copyright = "(C) 2015 Leo Davidson"
initData.version = "1.0"
initData.default_enable = true
End Function

Function OnBeforeFolderChange(beforeFolderChangeData)
Dim Cmd
If (beforeFolderChangeData.initial) Then
If (DOpus.FSUtil.ComparePath(beforeFolderChangeData.path, RootPath, "p")) Then
Set cmd = DOpus.Create.Command
cmd.SetSourceTab beforeFolderChangeData.tab
cmd.RunCommand "Set TREEROOT=""" & RootPath & """"
End If
End If
End Function[/code]

Thanks a lot, looks like this is what I've been looking for.