Assigning scripts/macros to keyboard shortcuts?

I’ve recently gotten around to creating some “json hack” keyboard shortcuts for properties panel functions that I use a lot. Thanks to Leo and Daniel for their awesome guidelines on this thread. During this process, I realized that the macro functionality in the Script menu is actually pretty robust, I had never used it before.

So now I’m wondering about the possibilities of creating a keyboard shortcut to combine two discrete actions; specifically in my case to switch the selection to X noteheads AND enable “suppress playback”. I recorded and saved a script for the task (below), but I can’t seem to figure out how to map it to a keyboard shortcut without using external software like Keyboard Maestro.

app:doCommand([[Edit.SetNoteheadSetOverride?NoteheadSetEntityID=noteheadset.Xnoteheads]])
app:doCommand([[UI.InvokePropertyChangeValue?Type=kEventMuted&Value=string: "true"]])

As far as I can tell, keycommands_en.js only takes a single command per keyboard shortcut, but I was wondering if there might be another native solution that I’m missing?

Also as a tiny wishlist idea, it would be super nice to be able to record macros and then set keyboard shortcuts to run those scripts directly from the preferences menu.

This is possible. To find out the proper syntax, record a macro of you running the script manually (for this, your script should be saved under something else than the original usermacro.lua file).
Here is how such a json entry looks on my system:

	{
		"Script.RunScript?ScriptPath=MYPATH/systembreak.lua" : [ "Ctrl+Return" ]
	},

That makes a lot of sense. Thanks Alexander!

For Mac users, this is easily done in System Preferences>Keyboard>Shortcuts>App Shortcuts. Your chosen key command is even displayed in the Dorico menu.

Is this still working??

wasted my afternoon to build a shortcut to guitar/technique/DeadNote

	{
			"Script.RunScript?ScriptPath="C:/Users/Claude Voit/AppData/Roaming/Steinberg/Dorico 3.5/Script Plug-ins/DeadNote.lua" : [ "MyKeyCommand" ]
		},

DeadNote.lua works fine from the menu

any Idea?

Windows uses back slashes for directory structures rather than forward slashes, doesn’t it?

Yep…

inverted the slashes to no awail :blush:

A. Which context (kGlobal, kEditable etc.) did you put the key command in?
B. When you run the key command, does Run Script appear on Edit > Undo?
C. Do you really need the script at all? Wouldn’t it make more sense to assign the key command to do whatever the script’s action is?

A. in kGlobal near “Script.StartRecordingMacro” : [ “Ctrl+Alt+Shift+W” ]
B. no
C. there is no key command for Dead note

C. Click the link at the very top of this thread. Read my instructions on that thread. They tell you how to record a script and then inspect it in order to see what Dorico’s actually doing behind the scenes. They then describe how to take that function and graft it into your keycommands file with an appropriate shortcut, thus creating a shortcut for something that isn’t officially assignable.

Turning the dead key property on looks something like this:

It’s the pink bit that you need to graft into your keycommands file.

Leo
I know how to graft a function into my keycommands file, have done it often.

what I try here, is to follow Alexander Plötz’s method (post #2 of this thread)
the goal is to trigger “DeadNote.lua” that is in my scripts folder

You appear to have an extraneous " before C:. Try removing it.

Thanks Alexander

I finally made it working…
something was wrong in the path… :nerd:
thanks to https://jsonlint.com I could validate my way thru

thanks Alexander, Leo and DanKreider

Claude

I tried to do that, pasted code before my first key command line (I think syntax is ok). When I run Dorico no key command (custom or default) works. i erased the code pasted and it works again. So I think I’m pasting it in the wrong context. Should I paste in kglobal, kwritemode or kmusiceditable? Or maybe is it a problem completely different?

Miguel, what are you trying to insert into your Keycommands file? The relevant context depends on what the function is.

I want to assign a key command to a macro file. It’s a test macro called ‘4x4_+10b_allegro’, that’s it:

local app=DoApp.DoApp()
app:doCommand([[Edit.SelectAtPoint?X=114&Y=171&AddToSelection=0&BlockSelection=0&NextSelectionAtPoint=0&SelectionTriggerAction=0]])
app:doCommand([[NoteInput.CreateTimeSignature]])
app:doCommand([[NoteInput.CreateTimeSignature?Definition=4/4&UseLocalOverride=0]])
app:doCommand([[NoteInput.CreateBarLine]])
app:doCommand([[NoteInput.CreateBarLine?Definition=10&UseLocalOverride=0]])
app:doCommand([[Edit.SelectAtPoint?X=159.5&Y=166.5&AddToSelection=0&BlockSelection=0&NextSelectionAtPoint=0&SelectionTriggerAction=0]])
app:doCommand([[NoteInput.CreateTempo]])
app:doCommand([[NoteInput.CreateTempo?Definition=Allegro moderato q = 120&UseLocalOverride=0]])

Then I copied this code:

	{
		"Script.RunScript?ScriptPath=MYPATH/systembreak.lua" : [ "Ctrl+Return" ]
	},

I rooted to my macro:

	{
		"Script.RunScript?ScriptPath=E:\PROYECTOS\DORICO\MACROS\4x4_+10b_allegro.lua" : [ "Ctrl+Num+0" ]
	},

I copied before the first custom key command in the appdata ‘keycommands_es’:

{
	"common" : {
		"contexts" : [
			
			{
				"context" : "kGlobal",
				"shortcuts" : [

					{
						"Script.RunScript?ScriptPath=E:\PROYECTOS\DORICO\MACROS\4x4_+10b_allegro.lua" : [ "Ctrl+Num+0" ]
					},
										
					{
						"Edit.BeamTogether" : [ "Ctrl+Num+1" ]
					},

When I saved it, key commands stopped working and they worked again when I erased this entry. I achieved to create a new entry in the keycommands_es working correctly in Dorico, as you explain in your link.

In JSONLint.com appears this error:

Error: Parse error on line 9:
...s": [					{						"Script.RunScript?Sc
--------------------^
Expecting 'STRING', '}', got 'undefined'

But I don’t understand it because it has the same format than the rest of the key commands.

had almost the same parse errors etc See earlier in thread

what saved me is
first enter the alexander plotz line as is
validate it in json
then in json
slowly replace path chunks one after the other
validate
replace another chunk
until you have entered and validated the complete line
then select all and replace in your json file
then it worked in Dorico
I cannot really say what made it work finally

Thank you SeeWhat! In my case, I replaced back slashes by fwd slashes in the path and JSONLint validated it without last comma (then added it). It works!

	{
		"Script.RunScript?ScriptPath=E:PROYECTOS/DORICO/MACROS/4x4_+10b_allegro.lua": ["Ctrl+Num+0"]
	}

It seems that JSON has some issues with back slash. Mac users don’t have to know it but Windows users do.