Dorico macro syntax question

Hello,

In addition to Dorico’s excellent features, I’ve created macros for some actions I use frequently.

As Daniel pointed out, coding is not officially supported because the environment might change in the future.

However, using small macros has made Dorico much faster for me. I’m aware that there is always the possibility that something might not work in the future.

I only have basic coding experience (I’ve tinkered a bit with website programming).

Until now, I have mainly recorded macros and made slight edits to them.

However, to speed up some processes, a bit more knowledge of the syntax would be necessary.

For example, I would like to create a small macro for a slide-in on guitar, which I use very often. This macro would create a grace note before the main note, which is a semitone lower, and then creates a glissando.

In theory, this shouldn’t be too hard to program.

Selected note:
NotePitch = x
Create grace note with Pitch = x - 1/2
Create glissando

My questions would be:

How do I access the information of the selected note (e.g., pitch, note duration)?
What is the syntax to define a variable?

Could someone help me with the syntax?

Apart from this specific case, the syntax would probably be helpful for other things as well.

Thanks a lot and greetings!

Johannes

1 Like

Unfortunately, it’s not possible to access any information about the selected note via the Lua API at the moment, which makes this kind of script impossible to write.

1 Like

I just played around with this a bit, and it should actually be doable, assuming that the source material that is not particularly unconventional. It’s all using Dorico’s on-board features directly, without any need for any algorithm beyond sending out the command strings for the features:

app:doCommand([[NoteInput.TransposeOrAddNotesToSelection?Definition=-m2]])
app:doCommand([[NoteInput.CreateGraceNote]])
app:doCommand([[UI.InvokePaletteButton?PaletteIndicatorID=kOrnamentsGlissandoFlat&PaletteSectionID=kOrnamentsGlissandiPanel&PropertyButton=false&SetOldValue=false&Set=true&UseLocalOverride=0]])

CAVEAT UTILITOR: for this to work, one must – in ‘Preferences>Note Input and Editing’ – set the ‘Direction of rhythmic movement when converting to grace notes’ option to ‘Backwards’.

1 Like

Daniel, thanks for your answer and sorry for my late response! It’s good to know about the limitations of macros.

Hi Alexander,

Thanks for your response! This pointed me in the right direction.

I cannot use the exact code as I occasionally also have to use guitar tabulature for guitar lessons and the added note is often shifted to another string.

But you mentioned the setting for grace note (backwards converting). This way I can use another code that works for me:

local app=DoApp.DoApp()
app:doCommand([[Edit.Copy]])
app:doCommand([[NoteInput.CreateGraceNote]])
app:doCommand([[NoteInput.NoteValue?LogDuration=kQuaver]])
app:doCommand([[NoteEdit.PitchDownChromatic]])
app:doCommand([[Edit.Paste]])
app:doCommand([[EventEdit.NavigateLeft]])
app:doCommand([[NoteInput.CreateGlissando]])
app:doCommand([[EventEdit.NavigateNextItemSamePosition]])

Using “copy and paste” may not be the most elegant solution but it works for me.

The grace note is selected so that I can easily adjust the enharmonic spelling, rhythmic value or the pitch.

I will assign a shortcut to it and this makes my work much faster! Magic (-;

Thanks a lot!

Greetings, Johannes

1 Like

@Johannes.Maas, glad I could help.

Since you express interest in exploring scripting in Dorico, as well as using scripts via keycommands, I’d like to encourage you to take a look at the ConsoleTools Lua framework that I have written. It gives you a good deal of flexibility for how to access scripts via shortcuts, and the included example scripts, together with their somewhat in-depth documentation (appendix C in the user manual), might give you some more pointers on how to approach utilising Lua in Dorico.

I also have written several libraries for use with ConsoleTools, all dealing with specific areas of workflow, which you can check out if you want to try out some ready-to-use scripting solutions.

Lastly, concerning your question about syntax – there are two types to consider:

One is the syntax of the Dorico command strings themselves, which usually is best learned by recording macros. Once you feel comfortable with this (and depending on what you want to do), you can experiment with generating command strings algorithmically where appropriate, instead of always hard-coding them. The auxiliary library included with ConsoleTools offers some functions that can streamline that process.

Then there is the syntax of the Lua language itself. There is no better resource to study it than Programming in Lua, written by one of the language’s developers. While it covers pretty much everything that you can do with Lua, it is structured in a way that will allow you to pick what you need, which won’t be much in the beginning.

1 Like

Hi Alexander,

Thanks a lot for your extensive response!

I’m indeed interested in learning more about Dorico macros, as they are one of the most powerful steps to speed up your specific workflow.

I have recorded and edited many macros for tasks I perform frequently, and I have assigned shortcuts to them via the keycommand file. This is great!

So, I feel that the next step would be to start “generating command strings algorithmically,” as you suggested.

However, as far as I understand it, generating command strings algorithmically would require drawing upon some data to be useful. (This could be either data provided by the program or data you input manually, with the former being the most useful case.)

I remember that I once tried to record a macro to extend the selection to the system track and then filter and copy chord symbols.

This was not possible because the string for system track selection requires a range of bars. To be useful, you would need to “read” the range of the current “normal selection” and transfer this data to the system track selection string.

What would be really useful is an extensive list of strings/variables that work in the program. (Maybe also some small examples how they could be implemented - but that would be the minor step.)

Is it really “zero” information that is accessible via the Dorico API as Daniel states?

Is there perhaps a place in the folder structure where this kind of information is accessible (since this “passive” data is not visible/accessible via recording macros)?

Thanks for pointing out the Console Tool framework. As far as I understand, the Console Tool framework is mainly a better and more guided way to organize scripts and assign shortcuts to them (which unfortunately is not natively supported by Dorico). I’ve also read the manual of the trial version.

Does the full version perhaps provide such a list as I mentioned before?

Thanks for your work and greetings,

Johannes