The script lets you configure a list of folders which will trigger a command whenever you enter them.
By default, it runs the command to turn on Flat View - Grouped:
For Flat View - Mixed, configure the script to run:
For Flat View - Mixed (No Folders), use:
You should also enable Preferences / Folders / Folder Behaviour / Cancel Flat View mode when folder is changed if you want Flat View to turn off again when you go to other folders.
You may also, if you wish, use the script to run a command which has nothing to do with Flat View. For example, you could change the font size or toggle the viewer panel when entering specific folders.
The script could be forked or extended to allow different commands when entering and leaving different sets of folders. I've chosen to keep things simple and easy to understand for now.
Another script, Trigger command in specific layouts, is very similar to this one, except it runs a command when new windows open, or when you change tabs in windows, if the windows come from particular layouts.
- Download: FlatViewAuto.vbs.txt (1.73 KB)
- Open Preferences / Toolbars / Scripts and drag the file to the list of scripts.
- Click OK.
Go to Prefences / Toolbars / Scripts, select the Flat-View Auto script, and click Configure; you'll see something like this:
Double-click either line to edit it, and remember to click OK or Apply back in the main Preferences dialog to save the change..
- v1.0 (16/Sep/2015) - Initial version.
The script itself:
If you just want to use the script, the FlatViewAuto.vbs.txt download above is easier.
The script code is reproduced here so people can find scripting techniques by browsing the forum without having to download & open lots of files.
Option Explicit Function OnInit(initData) initData.name = "Flat-View Auto" initData.version = "1.0" initData.desc = "Automatically turn on Flat View when entering configured folders" initData.copyright = "(c) 2015 Leo Davidson" initData.default_enable = true Dim vecDefFolders Set vecDefFolders = DOpus.Create.Vector ' Default folders / example config. vecDefFolders.push_back("/desktop") vecDefFolders.push_back("C:\Program Files\GPSoftware\Directory Opus") initData.config.FlatViewCommand = "Set FLATVIEW=On,Grouped" initData.config.FlatViewFolders = vecDefFolders initData.config_desc = DOpus.Create.Map( _ "FlatViewCommand", "Command to run when triggered.", _ "FlatViewFolders", "Folders which trigger the command.") End Function ' Helper Function Function IsPathInVector(fsu, path, vecFolders) IsPathInVector = False ' Resolve aliases, libraries, etc. to their real/absolute paths. path = fsu.Resolve(path) Dim testPath For Each testPath in vecFolders If (fsu.ComparePath(path, fsu.Resolve(testPath))) Then IsPathInVector = True Exit Function End If Next End Function Function OnAfterFolderChange(afterFolderChangeData) If (Not afterFolderChangeData.result) Then Exit Function ' Folder didn't change. End If ' Un-comment to make qualifiers (e.g. Alt, Shift, Ctrl) temporarily disable the script. ' If (afterFolderChangeData.qualifiers <> "none") Then ' Exit Function ' End If If (Not IsPathInVector(DOpus.FSUtil, afterFolderChangeData.tab.Path, Script.config.FlatViewFolders)) Then Exit Function End If Dim cmd Set cmd = DOpus.Create.Command cmd.SetSourceTab afterFolderChangeData.tab cmd.RunCommand Script.config.FlatViewCommand End Function