I just came across something that might help. Here goes:
$ defaults read /Library/Preferences/com.apple.HIToolbox.plist
{
AppleCurrentKeyboardLayoutInputSourceID = "com.apple.keylayout.Dutch";
AppleDefaultAsciiInputSource = {
InputSourceKind = "Keyboard Layout";
"KeyboardLayout ID" = 1337;
"KeyboardLayout Name" = QWERTY;
};
AppleEnabledInputSources = (
{
InputSourceKind = "Keyboard Layout";
"KeyboardLayout ID" = 26;
"KeyboardLayout Name" = Dutch;
}
);
AppleInputSourceHistory = (
{
InputSourceKind = "Keyboard Layout";
"KeyboardLayout ID" = 26;
"KeyboardLayout Name" = Dutch;
}
);
AppleSelectedInputSources = (
{
InputSourceKind = "Keyboard Layout";
"KeyboardLayout ID" = 26;
"KeyboardLayout Name" = Dutch;
}
);
}
This is on my system, where my custom keyboard layout (named “QWERTY”) is the default. Note that the KeyboardLayout Name
and KeyboardLayout ID
properties refer to the ID and name at the start of the .keylayout
file.
As you can see, defaults read /Library/Preferences/com.apple.HIToolbox.plist AppleCurrentKeyboardLayoutInputSourceID
still returns the string "com.apple.keylayout.Dutch"
. Is there a list somewhere of the available com.apple.keylayout
values? Is it possible to get such a value for a custom keyboard layout? ’Cause in that case, we could simply override the property.
Also, the AppleEnabledInputSources
, AppleInputSourceHistory
, and AppleSelectedInputSources
properties all seem to ignore the custom keyboard layout, as their values correspond to the native OS X keyboard layout I originally selected when running Setup Assistant.
Another update: Aha! Seems like there’s another plist
file from which we might be able to copy the settings.
$ defaults read ~/Library/Preferences/ByHost/com.apple.HIToolbox.*.plist
{
AppleCurrentKeyboardLayoutInputSourceID = "org.unknown.keylayout.QWERTY";
AppleDateResID = {
smRoman = 2;
};
AppleEnabledInputSources = (
{
InputSourceKind = "Keyboard Layout";
"KeyboardLayout ID" = 26;
"KeyboardLayout Name" = Dutch;
},
{
InputSourceKind = "Keyboard Layout";
"KeyboardLayout ID" = 1337;
"KeyboardLayout Name" = QWERTY;
},
{
"Bundle ID" = "com.apple.CharacterPaletteIM";
InputSourceKind = "Non Keyboard Input Method";
},
{
"Bundle ID" = "com.apple.KeyboardViewer";
InputSourceKind = "Non Keyboard Input Method";
},
{
"Bundle ID" = "com.apple.inputmethod.ironwood";
InputSourceKind = "Non Keyboard Input Method";
}
);
AppleGlobalTextInputProperties = {
TextInputGlobalPropertyPerContextInput = 0;
};
AppleInputSourceHistory = (
{
InputSourceKind = "Keyboard Layout";
"KeyboardLayout ID" = 1337;
"KeyboardLayout Name" = QWERTY;
},
{
InputSourceKind = "Keyboard Layout";
"KeyboardLayout ID" = 26;
"KeyboardLayout Name" = Dutch;
}
);
AppleNumberResID = {
smRoman = 2;
};
AppleSelectedInputSources = (
{
InputSourceKind = "Keyboard Layout";
"KeyboardLayout ID" = 1337;
"KeyboardLayout Name" = QWERTY;
},
{
"Bundle ID" = "com.apple.inputmethod.ironwood";
InputSourceKind = "Non Keyboard Input Method";
}
);
AppleTimeResID = {
smRoman = 2;
};
}
As you can see (AppleCurrentKeyboardLayoutInputSourceID
), apparently custom keyboard layouts get values like "org.unknown.keylayout.FOO"
where FOO
is the name of the keyboard layout (as specified in the .keylayout
file).
So, to let’s try setting all values to our custom keyboard layout, named QWERTY
and with ID 1337
(specified in the .keylayout
file):
sudo defaults write /Library/Preferences/ByHost/com.apple.HIToolbox.plist AppleCurrentKeyboardLayoutInputSourceID -string "org.unknown.keylayout.QWERTY"
Sadly, this doesn’t seem to work.
Update: @Lri discovered a reliable method — see his answer.