我刚遇到可能会有所帮助的事情。开始:
$ 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;
}
);
}
在我的系统上,这是我的自定义键盘布局(名为“ QWERTY”)的默认设置。请注意,KeyboardLayout Name
和KeyboardLayout ID
属性是指.keylayout
文件开头的ID和名称。
如您所见,defaults read /Library/Preferences/com.apple.HIToolbox.plist AppleCurrentKeyboardLayoutInputSourceID
仍然返回字符串"com.apple.keylayout.Dutch"
。是否有可用com.apple.keylayout
值的清单?是否可以为自定义键盘布局获得这样的值?因为在这种情况下,我们可以简单地覆盖该属性。
此外,AppleEnabledInputSources
,AppleInputSourceHistory
,和AppleSelectedInputSources
性能都似乎忽略了自定义的键盘布局,因为它们的值对应于在运行安装助手时,我最初选择的本地OS X的键盘布局。
另一个更新:啊哈!似乎还有另一个plist
文件可以用来复制设置。
$ 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;
};
}
如您所见(AppleCurrentKeyboardLayoutInputSourceID
),显然,自定义键盘布局获得的值类似于"org.unknown.keylayout.FOO"
where FOO
是键盘布局的名称(在.keylayout
文件中指定)。
因此,让我们尝试将所有值设置为我们的自定义键盘布局,命名QWERTY
和ID 1337
(在.keylayout
文件中指定):
sudo defaults write /Library/Preferences/ByHost/com.apple.HIToolbox.plist AppleCurrentKeyboardLayoutInputSourceID -string "org.unknown.keylayout.QWERTY"
可悲的是,这似乎不起作用。
更新: @Lri发现了一种可靠的方法-请参阅他的答案。