We tried this and several other approaches to no avail, are there any currently-working solutions to change the keyboard input language programatically?
#!/bin/bash
# Script to set the default keyboard layout to British
# Set the keyboard layout to British
/usr/bin/defaults write com.apple.HIToolbox AppleCurrentKeyboardLayoutInputSourceID -string "com.apple.keylayout.British"
# Clear the keyboard layout cache
/usr/bin/defaults delete com.apple.HIToolbox AppleEnabledInputSources
# Add the British keyboard layout to the list of enabled input sources
/usr/bin/defaults write com.apple.HIToolbox AppleEnabledInputSources -array-add '<dict><key>InputSourceKind</key><string>Keyboard Layout</string><key>KeyboardLayout ID</key><integer>2</integer><key>KeyboardLayout Name</key><string>British</string></dict>'
# Restart the HIToolbox process to apply changes
/usr/bin/killall -HUP SystemUIServer
echo "Default keyboard layout has been set to British."