Issues with Set Keyboard Layout (Monterey)

Again, this is after upgrading to Monterey.

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:

image

It works. However, every time, it opens up the keyboard preference window and shows an alert.

image

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:

  1. Restarting the Keyboard Maestro Engine.
  2. Removing and adding Keyboard Maestro Engine from Accessibility (Privacy).
  3. Restarting the computer.

Thanks!

1 Like

If all else fails, add actions to your macro to click the OK button?

Thanks! But that'll be worse than the switch keyboard hotkey that comes with the system. :joy:
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.

1 Like

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 did not have this problem in Big Sur. Something must have been changed in Monterey...

Yes, it is definitely new to Monterey, some attack on the “security” of third party input methods.

Thanks, Peter.

If I report this to Apple, how can I describe the issue so that Apple support team will understand that the problem is theirs to solve, not due to KM.

For this reason, I think it might be even better not to mention KM at all.

It's difficult. You can reference “any app that uses TISEnableInputSource/TISSelectInputSource to set the input to a third party input”.

I agree, if you refer to Keyboard Maestro specifically, they will just write it off as not their problem.

Third party input methods are often used for accessibility purposes, so the inability to easily switch to them is extremely annoying.

2 Likes

Thanks, Peter. I've submitted a request asking them to take a look at it. Hopefully, they will respond to it.

2 Likes

Hello, have you solved the problem? I got the exact same problem with you and wonder what is the dedicated app that can help the situation.

I use click menu script as a temporary solution.

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:

image

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.

1 Like

Thank you very much for your help!