Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better way to set default keyboard? #7

Open
mathiasbynens opened this issue Dec 18, 2013 · 2 comments
Open

Better way to set default keyboard? #7

mathiasbynens opened this issue Dec 18, 2013 · 2 comments

Comments

@mathiasbynens
Copy link
Owner

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

# ==============================================
# Set keyboard preferences
# ==============================================
defaults write /Library/Preferences/com.apple.HIToolbox AppleCurrentKeyboardLayoutInputSourceID "com.apple.keylayout.Finnish"
defaults write /Library/Preferences/com.apple.HIToolbox AppleDefaultAsciiInputSource -dict InputSourceKind "Keyboard Layout" "KeyboardLayout ID" -int 17 "KeyboardLayout Name" Finnish

# Delete the default layouts (US)
defaults delete /Library/Preferences/com.apple.HIToolbox AppleEnabledInputSources

# Enable Finnish layout
defaults write /Library/Preferences/com.apple.HIToolbox AppleEnabledInputSources -array '{ InputSourceKind = "Keyboard Layout"; "KeyboardLayout ID" = 17; "KeyboardLayout Name" = Finnish; }'
defaults write /Library/Preferences/com.apple.HIToolbox AppleInputSourceHistory -array '{ InputSourceKind = "Keyboard Layout"; "KeyboardLayout ID" = 17; "KeyboardLayout Name" = Finnish; }'
defaults write /Library/Preferences/com.apple.HIToolbox AppleSelectedInputSources -array '{ InputSourceKind = "Keyboard Layout"; "KeyboardLayout ID" = 17; "KeyboardLayout Name" = Finnish; }'
@Lendar
Copy link

Lendar commented Aug 2, 2015

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.

@Macxim
Copy link

Macxim commented Apr 17, 2017

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>'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants