Gracias al consejo de @user3439894, encontré una respuesta (necesitas ripgrep y https://github.com/myshov/xkbswitch-macosx instalado):
ec() print -r -- "$@"
ecerr() { ec "$@" 1>&2 }
function input-lang-set-darwin() {
# https://github.com/myshov/xkbswitch-macosx
# `hyperfine --warmup 5 'xkbswitch -s 3' 'xkbswitch -s 0' 'xkbswitch -se Persian-ISIRI2901' 'xkbswitch -se US'`
# they all ran about the same 77ms
local wanted="${1:l}" to='US'
case "$wanted" in
en*) to=US ;;
fa*|per*) to='Persian-ISIRI2901' ;;
toggle*)
case "$(input-lang-get-darwin)" in
U.S.) to='Persian-ISIRI2901' ;;
Persian*) to='US' ;;
esac
;;
*) ecerr "Not supported" ; return 1 ;;
esac
xkbswitch -se "$to"
}
function input-lang-get-darwin() {
defaults read ~/Library/Preferences/com.apple.HIToolbox.plist AppleSelectedInputSources | command rg -e '"KeyboardLayout Name" = "([^"]*)"' --replace '$1' --only-matching --color never
}
Otra opción es https://github.com/Lutzifer/keyboardSwitcher pero no pude construirlo sin xcode.
2 votos
Eche un vistazo a esta respuesta ¿Cambiar la distribución del teclado OSX ("fuente de entrada") mediante programación a través de terminal o AppleScript? . Acabo de probarlo, el código en "Adicionalmente", y funciona más rápido que:
cliclick kd:ctrl kp:space ku:ctrl
. Dicho esto, mientras estoy en Terminal Si pulsas ctrl+espacio, cambiarás entre los dos diseños que tengo, ¿por qué no puedes pulsar las teclas físicamente?