Regex for macro names? looking for a way to launch a conflict palette macro when input language is not EN

Here's an unpromising idea that hinges on an untested solution to the known intractable problem of simulating the trigger of a conflict palette.

Summary

How Do I Trigger Macro by Its HotKey From Another Macro? - #13 by peternlewis

Still interested? :wink: Read on.

To test if the solution has a chance of working, use this AppleScript to simulate keystrokes. Replace the examples keystrokes with the keystroke that you use to trigger your conflict palette.

use AppleScript version "2.4"
use scripting additions

tell application id "com.apple.systemevents"
--Examples:
-- key code "98" -- (F7)
-- keystroke "d" using {shift down,command down}-- (โ‡งโŒ˜d)
end tell

Create a new macro with TWO "Execute an AppleScript" actions and paste it into both.
Only one action will fail. Two might work (as they do on my Mojave system). :crossed_fingers:

Assign an unused trigger that is the same in all languages to the new macro.

Trigger the new macro.

If it fails to trigger your conflict palette, abandon this idea. The path ends here.

If it does trigger the conflict palette, try making a macro to:

  1. Store the current keyboard id to a variable.
  2. set the keyboard to your keyboard for English input.

Simulate the keystroke that triggers the conflict palette.

  1. Wait until any key is typed.
  2. Switch input back to the stored keyboard id.

To implement the macro:

  1. Use the output of the following solution to set a variable named "localKeyboardID":
    How to find active input language? (keyboard, foreign language) - #2 by ComplexPoint

  2. Insert the "Set Keyboard Layout To" action to an English keyboard.

  3. Insert the "Pause until the Key State Changes" action.

  4. Make an Execute an AppleScript that runs the script below.

use AppleScript version "2.4"
use scripting additions

tell application id "com.stairways.keyboardmaestro.engine"
	set inputSetting to getvariable "localKeyboardID" instance system attribute "KMINSTANCE"
	
	do script "<dict>
            <key>KeyboardLayoutID</key>
            <string>" & inputSetting & "</string>
            <key>KeyboardLayoutName</key>
            <string></string>
            <key>MacroActionType</key>
            <string>SetKeyboardLayout</string>
        </dict>"
end tell

Use the new macro to trigger your conflict palette.

Oh, yes, cross your fingers. Good luck!  ๐Ÿ€
1 Like