大多数情况下,我喜欢将“Caps Lock”映射到控制键。有时,我希望将其绑定到“Caps Lock”。我想在 shell 脚本中切换它,这样我就可以自动或通过键盘快捷键进行切换。
答案1
设置存储在 中~/Library/Preferences/ByHost/.GlobalPreferences*.plist
,但我不知道如何在不注销并重新登录的情况下应用更改。KeyRemap4MacBook 有一个命令行实用程序它允许禁用和启用设置,但它不适用于 PCKeyboardHack。
这只会改变一个键盘的设置,如果系统语言不是英语则不起作用。
tell application "System Preferences"
reveal anchor "keyboardTab" of pane "com.apple.preference.keyboard"
end tell
tell application "System Events" to tell window 1 of process "System Preferences"
click button 1 of tab group 1
tell sheet 1
tell pop up button 4
click
delay 0.1
if value is "⇪ Caps Lock" then
click menu item 2 of menu 1
else
click menu item 1 of menu 1
end if
end tell
click button "OK"
end tell
end tell
quit application "System Preferences"