A tool for scripted demos, KM issues that came up, & solutions

For a quick & dirty demo of a simple text editor, I made a screen recording, and “narrated” the demo by typing into the editor itself. KM is the perfect tool for typing the lines of my script into the editor window.

ie, in the demo video, one sees text appear, line by line -
"Welcome to TubeWriter"
"The world's first text editor especially for toothpaste packaging!"

Each line of narration to be entered was a macro in the “narration” palette, where the text was the macro name itself. Those macros all just pointed to a generalized routine which types in the current macro’s name. in special cases, I’d customize them to take other actions in the demo app.

I included some “stage directions” (reminders to self) which had no action.

the ‘Narration Action’ macro’s actions:
- Select All (to replace previous narration)
- get %ExecutingMacro% which gives the name of this step, trim off the “nn)” which I use to order them
- insert that text by typing - the pace that KM makes the text automatically appear is … chefs kiss
- other app - specific stuff

lastly there’s macros for “next narration”, and “reset narration”. Which keep track where I am in the script. So I have one key combo to simply "do the next thing."

Careful - This narration engine has no knowledge of the app it’s narrating. It just pastes over the text of any currently active text field.

a few KM questions / suggestions came up when automating the steps through this group - basically I needed to tell KM, "execute macro x of a group" :

  • would have expected KM to have some method for enumerating macros in a group, surprised not to find it, so “Next Narration” is powered by an applescript.

  • Likewise, no method to execute macros by variable name, if I could get that list.

  • The applescript interface to KM must awkwardly jump between addressing KM and KME. I understand there must be implementation reasons why their functionality is separate, but to the script writer, it feels arbitrary. Variables - which I see and edit in KM App - must come from KM Engine. Listing macros & getting their names: KM. Executing macros: KME…

tell application "Keyboard Maestro Engine"
	set nCount to (getvariable "narrationCount") as integer
end tell

tell application "Keyboard Maestro"
	set nextmacro to macro nCount of macro group "narration palette"
end tell
set macroname to name of nextmacro

tell application "Keyboard Maestro Engine"
	do script macroname
	return
	
end tell


demo narration palette Macros.kmmacros (24.1 KB)

That's an astute observation. However bear in mind that a list of macros running in the KME would not be very meaningful, because names of macros are not unique when the Engine deals with them. That's because the same macro can be running concurrently in the Engine. For uniqueness, I think the KM Engine provides UUIDs, which you can find on this page:

https://wiki.keyboardmaestro.com/Tokens

No method? You can do this by passing the name to an Execute AppleScript action.

of course, and that's exactly what I did. To be more specific, I could have said "no non-escaping to a scripting engine method."

wasn't a big deal, just a few lines of code - for someone who's comfortable with that. For non-applescripters, I bet they'd make use of a "native" KM action which runs a macro whose name can come from a text token. Specifically, this action-

Even though I see your point, I must point out that macro names are not unique, so "calling by name" be an error-prone feature. In fact, all your macros can have all the same name, and everything would still work fine.