I think it is possible to get the results that you want. Individual macros themselves do not let you add "conditionals" to the macro's triggers (that would complicate the design of KM quite a bit) but I think you can achieve the same result as follows....
Whenever the input language changes you can run a macro that will enable or disable macros as you deem appropriate. So in your example, whenever the input language changes to EN, you can enable the macro with this action:
And when the language changes to something else, you can do this action:
This way, your macros can show up in a conflict palette based on the value of your input language. Perhaps your follow-up question should be "How do I get a macro to run when the input language changes?" My answer would be, "How does your user change the input language?"
in the above macro when i launch the macro in EN input and press g then finder launches. yet if my input language is non EN (ie greek) then pressing the g wont launch the macro
does that make sense?
im trying to find a way to not duplicate each macro pallete with the appropriate keys for each language input i have (and i have a few :))
I see Nige is on the case. His answers are usually twice as helpful as mine, so I'll let him take the lead.
However I think I may know the reason. If you are talking about the keyboard language, changing the language from EN to GR will change a few of the keyboard's mappings. In particular, the letter G is changed to the character Gamma. You may be able to fix this by adding hotkeys for the Greek alphabet to your macros. In the case of "g.finder" you probably have to add a second hotkey containing the Gamma character.
Yes, literally the L key. That key on an UK/US keyboard maps to gamma on the Greek keyboard. I'm taking a punt that gamma==g in this situation.
But I suspect the matching is done "properly", by Unicode character. In which case your best bet is to change all your prefixes to things available, and easy to type, on both keyboard layouts. Numbers would be the obvious choice, remembering that the first 1 would show all macros whose name start with "1" -- including "1. Macro", "12. Macro", "134. Macro". A second 1 would reduce the list to "11. Macro", "112. Macro", etc. And you'd select "1. Macro" when "11. Macro" is also showing by hitting .
but the issue is that all macros wont work since all of them are mapped differently, plus as an academic i have many input language changes (arabic, hebrew, etc) i was trying to avoid a duplicating the macros per layout but since that there is no solution to that when uisng conflict pallets i guess
But you aren't "remapping" or duplicating macros, merely changing their names so you have consistently typable characters when a Conflict Palette appears. You're already using 1, 2, 3, 4... so you just carry on with that schema.
Using numbers isn't as "obvious" as, say, p for the password macro -- but you've the on-screen cues and you'll soon embed the commonly-used ones into muscle memory.
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).
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:
Store the current keyboard id to a variable.
set the keyboard to your keyboard for English input.
Simulate the keystroke that triggers the conflict palette.
Insert the "Set Keyboard Layout To" action to an English keyboard.
Insert the "Pause until the Key State Changes" action.
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! 🍀
Sorry for the DIY instructions with the bad AppleScript. If you're still needing a solution, here's a fully assembled macro to try out, arriving late as it is.
If you've moved on, I understand completely.
This macro launches a conflict palette and toggles the keyboard to the language that matches the conflict palette's expected input. When the palette closes, it toggles the input language back to the previous keyboard.
The download comes with 3 macros.
"A Macro" (triggered by F7)
"B Macro" (triggered by F7)
"Toggle keyboard layout for conflict palette" is the controller macro. (triggered by F8)
The first 2 make up the test conflict palette.
THe third controls the launch of the conflict palette, toggles the keyboard to the input layout that works with 2 and 3, and when the conflict palette closes, toggles the keyboard back to the previous keyboard.
To run the test:
Make sure the English U.S. keyboard layout is installed on your Mac.
Set your input keyboard to a keyboard layout that is not U.S. English.
Press F8.
A conflict palette with A Macro and B Macro will appear and the keyboard will switch to U.S. English.
Type a to play the Submarine sound. b plays the Blow sound. Typing escape closes the palette. In any case, you should see the keyboard switch back to previous keyboard.
To customize the macro's hotkeys, the hotkeys that launch the conflict palette, and the keyboard that get toggled, refer to the instructions included in the second, yellow comment,"Settings Instructions”, of the macro named, "Toggle keyboard layout for conflict palette"
Credits:
@Nige_S For taking the time to show me the correct and only way to trigger the conflict palette.
@ComplexPoint For the sine qua non jxa script that accomplishes what AppleScript cannot: retrieve the keyboard id.
For the JavaScript version, in recent builds, with the (now default) Modern Syntax option set behind the small chevron to the left of the code text field, we can simplify a little and write:
@ComplexPoint Thank you for taking time out for such a niche task!
I saw this for the the first time and thought for a moment: Oh, man, are there any nuggets that KM hasn't made available to automators, and what else am I overlooking?
I think, however, your script is still the thing without which this macro will brick. It seems so compact and self-contained, I wonder how hasn't it made its way into the KM 11.0.3 token bestiary?
Maybe I'm going about it wrong but what I'm getting out of the %KeyboardLayout% token is the display name, not the id. Instead of producing com.apple.keylayout.Greek, it simply outputs "Greek" or "German". Funny. Just to make sure I wasn't missing out on some hidden KM magic, I tried pasting "Greek" into the xml key, "KeyboardLayoutName", clearing the "KeyboardLayoutID" field, and pasting that action back into the Editor just to see if KM would fill it in somehow. It pasted OK, unsurprisingly errored:"
Failed to select keyboard layout, layout not configured
in macro "Display Text” (while executing Set Keyboard
Layout to "Greek"). Yep, it needs the id all right.
I really appreciate yours and others' help in keeping me current. I am going to post another macro version that replaces polling the accessibility window name with polling the window id after a while. I am really glad to have your solid, updated JXA version to add to it as well.