Open mathiasbynens opened 10 years ago
It didn't work on Yosemite 10.10: the new input source was still missing after restart.
I had to encode values in XML using that example on stackoverflow.
defaults write com.apple.HIToolbox AppleEnabledInputSources -array '<dict><key>InputSourceKind</key><string>Keyboard Layout</string><key>KeyboardLayout ID</key><integer>0</integer><key>KeyboardLayout Name</key><string>U.S.</string></dict>' '<dict><key>InputSourceKind</key><string>Keyboard Layout</string><key>KeyboardLayout ID</key><integer>19967</integer><key>KeyboardLayout Name</key><string>Russian-BG46</string></dict>'
After that the new input source was enabled by OS X. Restart was still needed in Yosemite, and re-log still wasn't enough.
FIY, this still doesn't work on Sierra 10.12.4.
# Enable French and Spanish layout
defaults write /Library/Preferences/com.apple.HIToolbox AppleEnabledInputSources -array \
'{ InputSourceKind = "Keyboard Layout"; "KeyboardLayout ID" = 1; "KeyboardLayout Name" = French; }' \
'{ InputSourceKind = "Keyboard Layout"; "KeyboardLayout ID" = 8; "KeyboardLayout Name" = Spanish; }' \
defaults write /Library/Preferences/com.apple.HIToolbox AppleInputSourceHistory -array \
'{ InputSourceKind = "Keyboard Layout"; "KeyboardLayout ID" = 1; "KeyboardLayout Name" = French; }' \
'{ InputSourceKind = "Keyboard Layout"; "KeyboardLayout ID" = 8; "KeyboardLayout Name" = Spanish; }' \
defaults write /Library/Preferences/com.apple.HIToolbox AppleSelectedInputSources -array \
'{ InputSourceKind = "Keyboard Layout"; "KeyboardLayout ID" = 1; "KeyboardLayout Name" = French; }' \
'{ InputSourceKind = "Keyboard Layout"; "KeyboardLayout ID" = 8; "KeyboardLayout Name" = Spanish; }' \
Whereas this seem to work after restarting.
defaults write com.apple.HIToolbox AppleEnabledInputSources -array-add '<dict><key>InputSourceKind</key><string>Keyboard Layout</string><key>KeyboardLayout ID</key><integer>1</integer><key>KeyboardLayout Name</key><string>French</string></dict>'
defaults write com.apple.HIToolbox AppleEnabledInputSources -array-add '<dict><key>InputSourceKind</key><string>Keyboard Layout</string><key>KeyboardLayout ID</key><integer>8</integer><key>KeyboardLayout Name</key><string>Spanish</string></dict>'
This is for OS X 10.8, but it might just work for 10.9 as well: https://github.com/hjuutilainen/dotfiles/blob/9198bacc8e8ea63bf441a3e313a93a2159037a34/bin/osx-system-defaults.sh#L84-L96