I have a follow-up question to this topic: Switch TO specific input source
Asmus posted this answer:
I came up with a bit nicer solution in AppleScript, given you know the name of the Keyboard Layout you want to switch to. Create a function like this:
on changeKeyboardLayout(layoutName) tell application "System Events" to tell process "SystemUIServer" tell (1st menu bar item of menu bar 1 whose description is "text input") to {click, click (menu 1's menu item layoutName)} end tell end changeKeyboardLayoutand then call it by
changeKeyboardLayout("English") changeKeyboardLayout("German")Be aware that the names of Keyboard Layouts are localized, i.e. on a german system the above example would need to call "Englisch" and "Deutsch".
So, I tried creating a script like this, for switching to Vietnamese on a Spanish system:
on changeKeyboardLayout("Vietnamita")
tell application "System Events" to tell process "SystemUIServer"
tell (1st menu bar item of menu bar 1 whose description is "text input") to {click, click (menu 1's menu item "Vietnamita")}
end tell
end changeKeyboardLayout
It's not working. It also doesn't work if I take out the quotation marks on either or both instances of the word "Vietnamita". Can you see what I'm doing wrong? Thanks.