Can I set a series of Hot Keys and store them in vars, and then trigger other Macros?

I have a set of 40+ Macros for managing window position. I'd share the whole macro set on here, but customizing the Trigger Hot Keys is very time consuming.

For example;

Set vars
2X2 = OPTION
LEFT = A
RIGHT = D

So that:
[ 2X2 ] + [LEFT] triggers Macro Move Window Left
(OPTION) + (A)

Then you can change:
2x2 = CONTROL+OPTION

So that:
[ 2X2 ] + [LEFT] triggers Macro Move Window Left
(CONTROL+OPTION) + (A)

That's not how you "trigger" one macro from another.
You call the second macro using Execute a Macro action.

Questions?

I understand that, and use Execute a Macro quite often.

I was hoping to create a shortcut set without having to edit the shortcut of every macro.

I'll try again...
Imagine you have 9 macros, each macro has it's own "Hot Key Trigger". They each use some combination of the option key and a letter:
[option q] - Top left
[option w] - Top middle
[option e] - Top right
[option a] - Middle left
[option s] - Middle Middle
[option d] - Middle right
[option z] - Bottom left
[option x] - Bottom middle
[option c] - Bottom right

but then you want to change all the macros to option+control:
[option+control q] - Top left
[option+control w] - Top middle
[option+control e] - Top right
[option+control a] - Middle left
[option+control s] - Middle Middle
[option+control d] - Middle right
[option+control z] - Bottom left
[option+control x] - Bottom middle
[option+control c] - Bottom right

Can this be done without setting the "Hot Key Trigger" for each macro?

In a word: No

Your choices are:

  1. Change the hot key trigger for each macro
  2. Add a hot key trigger for each macro
  3. Create a Macro Alias, and assign the hot key trigger, for each macro.

The only way to automate this is to perform #1 using a script.
I have drafted the below script as a starting point for you. It is incomplete and untested. But if you (or anyone) knows some AppleScript, you should be able to finish this script.
Sorry, but I don't have time right now to finish the script.

Example, Incomplete Script to Change Macro Trigger

property ptyScriptName : "Change Macro Trigger [Example]"
property ptyScriptVer : "1.1"
property ptyScriptDate : "2018-07-15"
property ptyScriptAuthor : "JMichaelTX"

(*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  NOTE:  This script is incomplete, and serves only as an outline
            of how to accomplish this task.  It has not had any testing
            beyond inspection of data in SD7.
            
            It will run as is, but does NOT make any changes.
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*)

tell application "Keyboard Maestro"
  
  set macroList to selected macros
  
  --- Make Sure at least ONE Macro is Selected ---
  
  if (macroList = {}) then
    error "You must select at least one macro."
  end if
  
  --- Loop Through All Selected Macros --
  
  repeat with oMacro in macroList
    
    tell oMacro
      set macroName to name
      set triggerList to every trigger

      repeat with oTrig in triggerList
        
        set trigXML to xml of oTrig
        
        # Check Trigger XML to see if it is Hot Key, and
        # has the proper Modifiers 
        (*
        MUST HAVE:
        --- HOT KEY ---
        <key>MacroTriggerType</key>
        <string>HotKey</string>
        
        AND
        --- OPTION KEY ---
        <key>Modifiers</key>
        <integer>2048</integer>
        *)
        
        ### Add Code to replace Modifiers Number in Trigger XML
        
        (*
      NOTE:  All Modifiers are combined into one Number
      
      CHANGE:
      --- OPTON KEY Only ---
      <key>Modifiers</key>
      <integer>2048</integer>
      
      TO:
      --- OPTION and CONTROL Keys ---
      <key>Modifiers</key>
      <integer>6144</integer>
      *)
      end repeat
    end tell
    
  end repeat -- of macroList
  
  
end tell


Example Trigger XML

<?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>92</integer>
  <key>MacroTriggerType</key>
  <string>HotKey</string>
  <key>Modifiers</key>
  <integer>2048</integer>
</dict>
</plist>


Learning AppleScript

If you are new to AppleScript and are interested in learning more, then I'd suggest you take a look at:

  1. AppleScript: Beginner's Tutorial
  2. Script Debugger 7 -- a full IDE for developing AppleScript.
    SD7 now comes with a 20-day free trial, and then will gracefully downgrade to the FREE SD7 Lite (which is still much better than Script Editor).

You can get lots of AppleScript help here in this forum, and in the Script Debugger Forum.

As I stated above, the answer is no.

Good news! I found time to finish my above script.

PURPOSE:

  • Change Triggers of All Selected Macros
    • FROM: OPTION Hot Key
    • TO: OPTION + CONTROL Hot Key
    • Normal Key Pressed Remains Unchanged

:warning: WARNING

  • This macro/script has had only LIMITED Testing.
  • Before you use for the first time you should:
    1. Duplicate one macro to use as a test.
    2. Select ONLY that one macro
    3. Then trigger the macro.

As always, feel free to post any questions, comments, issues, and/or suggestions that you might have concerning this macro.


Example Results

image


MACRO:   Replace Macro Trigger with OPTION Hot Key [Example]


#### DOWNLOAD:
<a class="attachment" href="/uploads/default/original/3X/1/c/1c7cd5c3e531843cc38aba303a496ab9afab7d05.kmmacros">Replace Macro Trigger with OPTION Hot Key [Example].kmmacros</a> (11 KB)
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**

---

### ReleaseNotes

Author.@JMichaelTX

**PURPOSE:**

* **Change Triggers of All Selected Macros**
   * FROM: `OPTION` Hot Key
   * TO:  `OPTION + CONTROL` Hot Key
   * Normal Key Pressed Remains Unchanged

	❗WARNING
		• This macro/script has had only LIMITED Testing.
		• Before you use for the first time you should:
				1. Duplicate one macro to use as a test.
				2. Select ONLY that one macro
				3. Then trigger the script.

**NOTICE: This macro/script is just an _Example_**

* It is provided only for _educational purposes_, and may not be suitable for any specific purpose.
* It has had very limited testing.
* You need to test further before using in a production environment.
* It does not have extensive error checking/handling.
* It may not be complete.  It is provided as an example to show you one approach to solving a problem.

**REQUIRES:**

1. **KM 8.2+**
  * But it can be written in KM 7.3.1+
  * It is KM8 specific just because some of the Actions have changed to make things simpler, but equivalent Actions are available in KM 7.3.1.
.
2. **macOS 10.11.6 (El Capitan)**
  * KM 8 Requires Yosemite or later, so this macro will probably run on Yosemite, but I make no guarantees.  :wink: 


**MACRO SETUP**

* **Carefully review the Release Notes and the Macro Actions**
  * Make sure you understand what the Macro will do.  
  * You are responsible for running the Macro, not me.  😉
.
* Assign a Trigger to this maro.
* Move this macro to a Macro Group that is only Active when you need this Macro.
* ENABLE this Macro.
.

**USE AT YOUR OWN RISK**

* While I have given this limited testing, and to the best of my knowledge it will do no harm, I cannot guarantee it.
* If you have any doubts or questions:
  * **Ask first**
  * Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.

---

![image|546x908](upload://504YQt6uMARU2JwuhuwRFG2XKL6.jpg)