Assigning Triggers Dynamically, if Possible?

Hi people

There was something I used to use with autohotkey years ago when I was windows user and now wonder is it possible with KM?

So, all keystrokes used by the script were written in one .ini file and linked to certain functions or labels as they are called in AHK, so when they are pressed, the script would know which function or label to run.

As I make accessibility enhancements for blind that is screen reader users, and we all use only keyboard to work on computer, something like that would be really useful if possible in KM.

The way it works currently in the KM is fine, just a bit slow when user wants to change keystrokes for more then a few macros. I'm just curious to hear about some alternatives if there are any.

Thanks in advance

If you are asking if there is some sort of "text" interface to Keyboard Maestro, no, there isn't.

However Keyboard Maestro itself is highly scriptable, including the ability to create or delete macros. For example, see:

So you could, for example, have a text file with your mappings, and then you could have a macro that created the macros for those mappings (deleting any existing macros first presumably).

Hey Peter

Thanks for sharing this, it is sort of thing that would be really useful.

But is there a way to have list of keystrokes linked to already existing macros, so if keystrokes are changed on this list, the triggers would get changed on macros too?

Or maybe it would be better to ask this: Is it possible to assign triggers to a macro through the scripting?

If I understood you correctly, you said that it's possible to create macros through scripting.

So if there's possibility to select macro groups and macros through scripting, and assign or change their triggers through scripting too, then I'd be able to create custom functionality to get what I actually want.

Thanks

Doable via AppleScript

Add Trigger to Selected Macro
set triggerXML to "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
   <key>FireType</key>
   <string>Pressed</string>
   <key>KeyCode</key>
   <integer>122</integer>
   <key>MacroTriggerType</key>
   <string>HotKey</string>
   <key>Modifiers</key>
   <integer>2048</integer>
</dict>
</plist>
"

tell application "Keyboard Maestro"
   set theMacro to item 1 of (get selected macros)
   tell theMacro
      make new trigger with properties {xml:triggerXML}
   end tell
end tell

Adds the hotkey trigger F1 to the selected macro.

Doable.

1 Like