Switch input layout (keyboard) from the command line for macOSX
kbswitch
A keyboard switching program for the command line.
Code is from this stackoverflow question
Installation
- requires xcode command line tools
- run
make - copy
build/kbswitchto place in path
Usage
kbswitch listlist all available inputskbswitch com.apple.keylayout.ABCfor English (macos Ventura)kbswitch com.apple.inputmethod.Kotoeri.RomajiTyping.Japanesefor Japanese (macos Ventura)
Notes
There is an objective-c version kbswitch.m that can be compiled with
clang -framework Carbon -framework Foundation filename.m -o filename. However, this doesn’t necessarily work as is because it requires com.apple.keylayout prepended to the keyboard layout.
Switch to English keyboard in Vim
If you want to switch from (other language) to English when going from insert mode to normal mode in vim/neovim, add this to your config:
inoremap <ESC> <ESC>:execute 'silent! !kbswitch com.apple.keylayout.ABC'<CR>:echon ''<CR>
Note that the exectuble must be in your $PATH.