The AppleScript that was working perfectly in Big Sur stopped working:
changeKeyboardLayout("Squirrel")
on changeKeyboardLayout(layoutName)
tell application "System Events"
tell process "TextInputMenuAgent"
click menu item layoutName of menu 1 of menu bar item 1 of menu bar 2
click menu bar item 1 of menu bar 2
end tell
end tell
end changeKeyboardLayout
I went back to try the Keyboard Maestro action:
It works. However, every time, it opens up the keyboard preference window and shows an alert.
I have clicked "OK" several times. It still pops up.
The behavior is consistent with all third party keyboards.
@peternlewis, is there a permission somewhere I should set/reset?
Edit: I have tried:
Restarting the Keyboard Maestro Engine.
Removing and adding Keyboard Maestro Engine from Accessibility (Privacy).
Thanks! But that'll be worse than the switch keyboard hotkey that comes with the system.
The purpose of the macro is to make switching to the target keyboard smooth and efficient. If all fail, I'll use a dedicated app for the purpose. But I prefer to do it with Keyboard Maestro so that I may avoid installing another app.
I'd guess the issue is with any application setting the keyboard to a third party input method. I don't know if there is some way to sign or authorise third party input methods, or some security permission that would allow Keyboard Maestro to set them without complaint.
I have Bartender's AppleScript support to simulate menu bar item click.
Here is a sample script:
changeKeyboardLayout("Squirrel - Simplified")
on changeKeyboardLayout(layoutName)
tell application "Bartender 4"
activate "com.apple.TextInputMenuAgent-Item-0"
end tell
tell application "System Events"
tell process "TextInputMenuAgent"
click menu item layoutName of menu 1 of menu bar item 1 of menu bar 2
end tell
end tell
end changeKeyboardLayout
In the above code, Squirrel - Simplified is the name of the target input method. See below:
The problem is that if the current window is Alfred search window, then Alfred will be deactivated. There is another post to discuss about a solution for this issue.