Automate Tasks Requiring Often-repeated Mode Switches With a Lua Library for ConsoleTools

As part of the release of five scripting libraries for the ConsoleTools Lua framework, I today publish the Window Menu Commands Tool Library (the four other releases are: Tuplets, Casting-off, Cueing and Selecting).

It gets it name from the fact that it is largely built around recreating the commands available through Dorico’s Window menu, which, admittedly, does not sound particularly exciting. However, the library does become rather powerful by providing tools for changing the Dorico mode which are capable of hooking – meaning that such changes can be linked up with other Lua scripting tools, thereby automating the sometimes tedious mode changes necessary for certain tasks.

If you regularly find yourself frustrated by frequent mode changes (or tripping up over them), looking into this library might very well be worth your while.

GIF – Engrave Mode edits (effectively) from Write Mode:

EM edits from WM

GIF – Recall custom panel configuration presets:

custom panel configuration

GIF – Cycle through window split modes:

cycle through window split modes

You can download the library below. The zip file contains the actual Lua script, and a PDF with the complete documentation:

ConsoleTools Tool Library - Window Menu Commands 1.0.zip (566.6 KB)

Note: Do not try to run the lua file directly in Dorico (via the Script menu). You will need the ConsoleTools framework in order to use the library. However, the free limited version will suffice to try it out. You can find more information about ConsoleTools in this thread.

Feel free to ask any questions about the library here. (Any questions specifically about ConsoleTools should be posted in the thread about the framework itself, though.)

As with previous releases, it should be noted that this library is somewhat of a “public beta”. If you find that something does not work as should be expected from the documentation, please feel free to get in touch with me. Further down the road, I plan to re-include the library (with any bug fixes) in a larger one, which will offer a variety of other script-enhanced Dorico tasks.

4 Likes

I already use a simple script to Hide Stems in Write mode:

app:doCommand([[Filter.NotesAndChords]])
app:doCommand([[Window.SwitchMode?WindowMode=kEngraveMode]])
app:doCommand([[UI.InvokePropertyChangeValue?Type=kNoteHideStem&Value=true]])
app:doCommand([[Window.SwitchMode?WindowMode=kWriteMode]])

What benefits does “hooking” bring, that my script does not provide?

With something like hiding stems (which I used in the GIF above mainly for it being an immediately tangible example), the benefits are not glaringly obvious. One advantage about this particular type of edit that I can see (putting aside, for the sake of simplicity, your filtering operation) is that you might have times where you want to return to Write Mode, and other times where you do not want that. With the classical approach, you can have two different scripts, one including the mode changes, and one not including them, but still, you will have to go to some extra lengths in your JSON hacking to make them apply at the right time. But with ConsoleTools, you can have a simple “Hide stems” tool, set up from the command string, like so:

addTool("Hide stems in EM",[[UI.InvokePropertyChangeValue?Type=kNoteHideStem&Value=true]],"hideStemsEM")

… and you can have another tool for the same thing from Write Mode, by simply hooking in the existing tool:

addTool("Hide stems in WM",{(fromLuaLibrary("switchBetweenTwoModes",,"_nl._lib.window.lua")),3,2,{"hideStemsEM"}},"hideStemsWM")

Then, instead of having these tools on fixed keycommands (although you can do that too with ConsoleTools), you load the appropriate tool ad hoc onto a tool slot of your choice.

As with the ConsoleTools framework itself, I tried to set up things in a way that allow for a variety of ways to use tools – that element of abstraction keeps thing nicely malleable, but also puts me in a tough spot when trying to point out what you can do with it. You can do a lot of cool things with it, which hopefully will be useful to a lot of users, but laying those things out comprehensively (including the different approaches that may be available to do the same task) is a bit Sisyphean.

But let’s consider this (still somewhat artificial) scenario, which also highlights a bit the general flexibility of ConsoleTools:

First of all, let’s assume that the “switchBetweenTwoModes” tool from the library is part of the user’s tool collection, with their tool setup file including this line:

addTool("Mode>...>Mode",{(fromLuaLibrary("switchBetweenTwoModes","_nl._lib.window.lua"))},"_sw2m")

Now that user is working (predominantly in Write Mode) on a score that contains a lot of glissando notations. They realise that they are coming across many cases where the start offset of a glissando line needs a bit of an adjustment, but the needed amount varies slightly from case to case. Since our imaginary user is somewhat savvy with Dorico’s macro recording, they know how to get to the appropriate command string, so they could make their life easier with some custom scripts. But still, they would need a single script for each needed offset value (including the mode switches), and if they wanted those available via keycommands, they would have to dive into their keycommands.json, which is probably the point at which they would decide that it’s not worth the effort.

But with the tool from the line above, after having figured out what the command string looks like, they just have to enter this into the console:

set(1,"_sw2m",{3,2,[[UI.InvokePropertyChangeValue?Type=kGlissandoLineStartDX&Value=string: "1/2"]]})
set(2,"_sw2m",{3,2,[[UI.InvokePropertyChangeValue?Type=kGlissandoLineStartDX&Value=string: "2/2"]]})
set(3,"_sw2m",{3,2,[[UI.InvokePropertyChangeValue?Type=kGlissandoLineStartDX&Value=string: "3/2"]]})

… and they would immediately have three different offsets at their fingertips (i.e., available on their first three ConsoleTools tool slots), with the mode switches handled automatically.

For anything other than mere one-off use, there are more elegant ways to set up something like this in ConsoleTools, which I won’t get into here, but hopefully this gives an impression of how the hooking functionality can be useful.

One thing that looking at your script brings to mind is that I probably should also allow for multiple hooks, so that one could set up a filter operation, like you did. I do believe that this kind of functionality should already be in there, it’s just not exposed; I’ll look into it and maybe update the library. Be that as it may (and coming full circle to the topic of ConsoleTools’s versatility), you could probably already build up something equivalent in various ways with the currently available functionality, for example by incorporating the Filter library, which allows for filtering from Engrave Mode.

2 Likes