我似乎无法弄清楚如何使用 Applescript 选择正确的按钮。我开始学习 vim 并希望能够在 Caps Lock 和 Ctrl 之间切换 Caps Lock 键。我已经标记了我需要完成的步骤。
我找到了(这篇文章),但它似乎有点 hacky。也许这是它应该的方式,但它显示了系统偏好。每次我使用它时的窗口,不像(此代码)切换fn键并且工作无缝。
有人可以提供一些建议吗?
这是我的代码:
tell application "System Events"
tell application "System Preferences"
reveal anchor "keyboardTab" of pane "com.apple.preference.keyboard"
end tell
-- [STEP 1] set mod_keys to value of output from within "Modifier Keys..."
set mod_keys to button "Modifier Keys..." of tab group 1 of window 1 of application process "System Preferences"
-- I would prefer not to have to click the mod_keys because I don't want the window popping up but if it's necessary then okay
click mod_keys
-- [STEP 2] set cl_key to the second dropdown of mod_keys
set cl_key to menu item 2 of menu 1 of pop up button 4
set cl to value of cl_key
if cl is menu item 2
set q to menu item 2 of menu 1 of pop up button 4
else
set q to menu item 1 of menu 1 of pop up button 4
end if
end tell
-- This is just to make sure it works, but may be unneccessary
if application "System Preferences" is running then
tell application "System Preferences" to quit
end if
return q
这是修改器键屏幕截图: