Overview:
The script lets you configure a command which will be run whenever you open specific layouts, and another command when you switch tabs in specific layouts.
You can use this to apply changes to windows or tabs of particular layouts, where the thing you want to change is not part of the state which layouts normally save and restore.
By default, it comes pre-configured with example commands which change specified layouts to use fonts 150% the size you have configured for everything else:
-
When new windows open from matching layouts, it runs the command to set the font size to 150% on both sides of the lister:
Set FONTSCALE=150,both
-
When you change tabs in a matching layout, it runs the command to set the active tab's font size to 150%:
Set FONTSCALE=150
Another script, Trigger Flat View (or any other command) in configured folders, is similar to this one, but can run a specified command when you change folders, based on the path you change to.
Installation:
- Download: LayoutCommand.vbs.txt (2.7 KB)
- Open Preferences / Toolbars / Scripts and drag the file to the list of scripts.
- Click OK.
Configuration:
Go to Prefences / Toolbars / Scripts, select the Layout Command script, and click Configure.
Double-click lines to edit them.
When done, remember to click OK or Apply back in the main Preferences dialog to save any changes.
When editing the layout names, a window will open allowing you to type one per line, like this:
The configuration options are as follows:
-
CommandOpen: The Opus command which will be run when you open new windows via one of the named layouts. Set to a blank string to not run any command when new windows open.
-
CommandTab: The Opus command which will be run when you change tabs in one of the named layouts. Set to a blank string to not run any command when changing tabs.
-
OpenFirstOnly: If set to True, CommandOpen will only be run in the first tab of each lister in the layout. This is useful if the command affects the lister as a whole, or if it already affects multiple tabs when only run once.
If set to False, the command will be run once in each tab of each lister in the layout. That is useful if the command only affects individual tabs, and you want what it does to happen to all of them as soon as the window opens.
-
Layouts: This is the list of layout names which will trigger the command.
If you open a window which is not related to one of the named layouts, the script won't do anything to that window.
The layout names should match those in Preferences / Layouts and Styles / Layouts. If your layouts are organised into folders, use
\
to specify their names, similar to a file path. For example,Test\Videos
would match the layout shown below:
History:
- v1.1 (21/Nov/2017) - Added similar command when changing tabs.
- v1.0 (21/Nov/2017) - Initial version.
The script itself:
If you just want to use the script, the LayoutCommand.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 = "Layout Command"
initData.version = "1.1"
initData.desc = "Automatically run a command when specific layouts open or change tabs"
initData.copyright = "(c) 2017 Leo Davidson"
initData.default_enable = true
Dim vecDefLayouts
Set vecDefLayouts = DOpus.Create.Vector
' Default layouts / example config.
vecDefLayouts.push_back("My Layout 1")
vecDefLayouts.push_back("My Layout 2")
initData.config.CommandOpen = "Set FONTSCALE=150,both"
initData.config.CommandTab = "Set FONTSCALE=150"
initData.config.OpenFirstOnly = True
initData.config.Layouts = vecDefLayouts
initData.config_desc = DOpus.Create.Map( _
"CommandOpen", "If set to a command, it will be run when a lister from a matching layout opens.", _
"CommandTab", "If set to a command, it will be run when you change tabs in a matching lister.", _
"Layouts", "Names of layouts which the command(s) should be run for.", _
"OpenFirstOnly", "If True, CommandOpen is only run in the first tab when a new window opens; otherwise it is run once per tab.")
End Function
' Helper Function
Function IsNameInVector(name, vecNames)
IsNameInVector = False
Dim nameU
nameU = UCase(name)
if (nameU = "") Then
Exit Function
End If
Dim testName
For Each testName in vecNames
If (nameU = UCase(testName)) Then
IsNameInVector = True
Exit Function
End If
Next
End Function
Function OnOpenLister(openListerData)
If (Script.config.CommandOpen = "") Then
Exit Function
End If
' Un-comment to make qualifiers (e.g. Alt, Shift, Ctrl) temporarily disable the script.
' If (openListerData.qualifiers <> "none") Then
' Exit Function
' End If
If (Not openListerData.after) Then
OnOpenLister = True ' Ask to be called again when all the tabs are open.
Exit Function
End If
If (Not IsNameInVector(openListerData.lister.layout, Script.config.Layouts)) Then
Exit Function
End If
Dim cmd, tab
Set cmd = DOpus.Create.Command
For Each tab in openListerData.lister.tabs
cmd.SetSourceTab tab
cmd.RunCommand Script.config.CommandOpen
If Script.config.OpenFirstOnly Then
Exit For
End If
Next
End Function
Function OnActivateTab(activateTabData)
If (Script.config.CommandTab = "") Then
Exit Function
End If
' Un-comment to make qualifiers (e.g. Alt, Shift, Ctrl) temporarily disable the script.
' If (activateTabData.qualifiers <> "none") Then
' Exit Function
' End If
If (Not IsNameInVector(activateTabData.newtab.lister.layout, Script.config.Layouts)) Then
Exit Function
End If
Dim cmd
Set cmd = DOpus.Create.Command
cmd.SetSourceTab activateTabData.newtab
cmd.RunCommand Script.config.CommandTab
End Function