Share your AHK macros

I’ve been looking into AHK for macros, and I thought a new thread could be a good place to share scripts. I find the AHK online documentation daunting, but I’m wanting to learn so I can customize common command strings.

For starters, here are a couple macros I’d like to create (probably going to use F4-F12, with Shift, which gives me 18 total spots):

  1. Hide all signposts
  2. Select to end of flow
  3. Move selected notes to upstem voice (or down)

Thanks in advance to Romanos and others for your help!

If you have shift+end set as a shortcut for select to end of flow, you could do

F4::send +{End}

where the + sign is shift.


send !v {Down 4} 
send {Right} 
send {Enter}

assigns F9 to hiding the signposts, but in a different way.

!v means alt v, to open the View menu on windows.
send down 4 presses down arrow four times, send right right arrow once, send enter enter.
I had to keep this in separate lines to slow i down a bit, otherwise it would have been to fast for Dorico (?) to keep up.

Two different ways of doing two of the things on your list!

Thanks! I’ll try this out tonight. Helpful to see it explained.

Wouldn’t Dorico just interpret key commands one at a time, and compile a backlog of the ones it hadn’t gotten to yet?

Same idea, but to set rhythmic grid directly:

;= rhythmic grid
#a::Send, !r{down 3}{Right}{Enter} ;whole
#s::Send, !r{down 3}{Right}{down}{enter} ;dotted half
#d::Send, !r{down 3}{Right}{down 2}{enter} ;1/2
#f::Send, !r{down 3}{Right}{down 4}{enter} ;1/4
#g::Send, !r{down 3}{Right}{down 6}{enter} ;1/8th
#h::Send, !r{down 3}{Right}{down 8}{enter} ;16th

Steve, sorry if this is a dumb question, but can you explain the commands?

What is AHK?


Yeah, dumb- asking a question to learn about something! :wink: :stuck_out_tongue:

Autohotkey has a whole scripting language, with tons of commands, (and more) and rules for how and in what order the lines are executed.

So the first line:
#a:: ← the keystroke (Windows Key+a) that will invoke the command. Double full colons separate it from the command string
Send, ← the command. In this case, “send the following characters”. A comma delineates it from the next part of the string.
!r <–! means the alt key, so this renders the keystroke alt+r. and
{Down 3} ← down arrow key 3 times

‘;’ (semicolon), ‘comments out’ the rest if the line it is on, so a comment that not get executed can be placed there.

‘!’ means alt, ‘#’ means Windows logo key, ‘+’ is shift and ‘^’ is ctrl.

The words wrapped in curly brackets are specific keys- using the brackets facilitates sending the key instead of all the letters that spell it.

So when I hit Win+a, autohotkey types: alt+r down arrow thrice, right arrow, enter

Ok, this is great! After Here’s a script for upbow (F4) and downbow (F5):

send +{P}
send {U}
send {Enter}
sleep 100
send {Enter}

send +{P}
send {D}
send {Enter}
sleep 100
send {Enter}

NOTE: I changed the shortcuts in the playing techniques editor to U and D for their respective bowings. Not sure why the “sleep” delay was necessary, but the script didn’t work until I added it.

Thanks Steve, makes sense! MUCH easier than trying to sort through the AHK manual. It’s fine, just info overload.

I’m going to map #a, #s, and #d to a grid of sixteenth, eighth, and quarter notes. Awesome.

As an aside, what’s this at the beginning of the script?

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

Here’s one I’ve used in the past:

+!c::© ;control-alt-shift-c yields copyright symbol

It seems that it doesn’t. Using separate lines was my first step to make it work, next step would be to add a sleep command just like you did in one of your macros.

Thanks for those links Steve. I have to confess I read them and still had no clue. Too many unfamiliar words in the descriptions.

I guess I’m just going to leave them in the script, maybe delete stuff after the semicolon to clean it up.

Curious: does everyone who uses AHK just have one script with all the Dorico shortcuts?

Ok, here’s one that uses F6 to change all selected notes to Upstem Voice 1. Super-helpful for avoiding chord mode (sorry Marc!!) =D =D

send !e {Up 5} 
send {Right} 
send {Up 2}
send {Right} 
send {Enter}

No problem… I can do it without AHK and without chord mode, thanks to Leo:

  1. Select the notes
  2. Invoke context menu
    3.Press “vc” keys
    Much faster to do than to describe :wink:
    Tell me when you find a way to copy lyrics in tuplets without chord mode, that’s the tricky part!!!

They tell AHK to do certain things, or to default to certain methods. With these simple scripts those lines don’t matter, but I would leave them in, since they don’t hurt anything, and might help later.

I guess I’m just going to leave them in the script, maybe delete stuff after the semicolon to clean it up.

The texts after the semicolon are comments, e.g., to tell you what the command on that line does. You will be happy later if you keep them, when your script grows and you are wondering what the heck that line was supposed to do. :wink:

Curious: does everyone who uses AHK just have one script with all the Dorico shortcuts?

I use one script per each : Cubase, Dorico, Web Browser, and a global one. ahk allows you to have each script active only when you’re in the program, via the “SetTimer” function.

Finally to make things easier you should download SciTE4Autohotkey, which colors the text according to the syntax. See pic.

All that said, once Lua scripting becomes robust in Dorico, ahk will be redundant, I think.

Marc, what are “vc” keys??

Also, I still don’t understand the connection of chord mode to copying lyrics to tuplets. I read the thread someone posted. Am I incorrect that it’s just a matter of selecting both the lyric AND the tuplet to copy? What am I not understanding? Thanks.

Dear Dan,
It’s the letter v (like voice) and letter c (change)
You are right that it’s compulsory to select both tripkets and lyrics to have the latter properly distributed. If you copy them without q mode engaged on a staff that is homorhythmic to the source, you delete the notes of the triplet (as far as I remember).

One thing very useful I discovered to multiply the power of AHK macros is to use custom combination hot keys:

press “f5” keep it pressed then press “1” to fire the macro
this offers you thousands of new Key shortcuts on the same physical keyboard

f5 & 1:: to fire macro 1
f5 & 2:: to fire macro 2
f5 & 3:: to fire macro 3
f5 & 4:: to fire macro 4


1 Like