Auto-select certain files when entering certain folders

This script add-in will make Directory Opus automatically select certain files when you go into certain folders.

You can configure the script to set the files and folders it reacts to. The folder paths can use wildcards.


To use the script, download the .vbs.txt file below, then drag and drop it to Preferences / Toolbars / Scripts, and click Configure on the new entry to set it up.

Special_Auto-Select.vbs.txt (1.46 KB)

The script code is also reproduced here to help people looking through the forum for scripting techniques:

' Called by Directory Opus to initialize the script
Function OnInit(initData)
	initData.name = "Special Auto-Select"
	initData.desc = "Automatically select specific files when entering certain folders."
	initData.copyright = ""
	initData.version = "1.1"
	initData.default_enable = true

	Set vecDefFolders = DOpus.Create.Vector
	' Default folders / example config.
	vecDefFolders.push_back("*\Directory Opus :: dopus.exe")
	vecDefFolders.push_back("*\Outlook :: Outlook.pst")
	vecDefFolders.push_back("C:\Passwords :: File4.txt")

	initData.config.FolderPatterns = vecDefFolders

	Set mapDescs = DOpus.Create.Map
	mapDescs("FolderPatterns") = "Folder path wildcards and files to select. Put :: between the wildcard and the filename. Example: ""*\Directory Opus :: dopus.exe"" selects ""dopus.exe"" when you go into any folder called ""Directory Opus""."
	initData.config_desc = mapDescs
End Function

' Called after a new folder is read in a tab
Function OnAfterFolderChange(afterFolderChangeData)
	For Each configPattern in Script.config.FolderPatterns
		configSplit = Split(configPattern, "::", 2)
		Set folderPattern = DOpus.FSUtil.NewWild( trim( configSplit(0) ) )
		If (folderPattern.Match(afterFolderChangeData.tab.path)) Then
			Set cmd = DOpus.Create.Command()
			cmd.SetSourceTab afterFolderChangeData.tab
			cmd.RunCommand "Select PATTERN=""" & trim( configSplit(1) ) & """ EXACT SETFOCUS DESELECTNOMATCH"
			Exit Function
		End If
	Next
End Function

Thank you so much, Leo. You are amazing.

Neat. No more searching for the right exe in the C:\program files folder now. Maybe you could expand it to also handle subfolders?

Maybe use SelectEx: Command: SelectEx (extended Select command)
It supports folders and files, regexes for both (path and item) and will scroll to any auto-selected item as well (if enabled). Watch the "Auto-Selection" description at the bottom and the AUTO cmdline switch.

Yes, that also looks very promising. However, i couldn't get it to work for some reason.
i use follwowing syntax: C:\Program Files\VideoLAN\VLC => vlc.exe

There's also this script error message.

SelectEx: Fehler in Zeile 671, Position 3
SelectEx: Unerwarteter Quantifizierer (0x800a139a)

By the way, i already played around with your very interesting script, and saved some selections. Is it normal, that it would remember saved selections only for one Opus session, using "save selection toundfrom" a file?

You're syntax is fine and tested to work (here at least), but let's move over to the SelectEx thread.. beam.. o)

Ok!

I can't see anything stopping the existing script from working with sub-folders already.

If you want it to auto-scroll to the selected item, I think you just need to add MAKEVISIBLE after SETFOCUS.

Leo, you're right. I had a typo (missing blank space after ::slight_smile: in the old list of paths and applications, which must have caused that red error icon. So, all is fine.

This script is great! However when the file is auto-selected it does not preview in the viewer pane until manually selected. Is there a way to have the file both auto-selected and previewed?

Untested, but after this line:

cmd.RunCommand "Select PATTERN=""" & trim( configSplit(1) ) & """ EXACT SETFOCUS DESELECTNOMATCH"

Add this extra line:

cmd.RunCommand "Show FILE=""" & afterFolderChangeData.tab.path & "\" & trim( configSplit(1) ) & """ VIEWPANECMD=open"

(EDIT: Corrected missing & mentioned in the two posts below this one.)

Something like that should work. If it doesn't work, I can fix it tomorrow.

Thanks for the quick reply! When I tried to upload it there was a parse error for some reason...

Try inserting & before afterFolderChange ....

1 Like

Thanks that worked!