如何使用AppleScript的切换Caps Lock键是Ctrl键 [英] How to use AppleScript to switch Caps Lock Key to be Ctrl Key
问题描述
我似乎无法弄清楚如何选择与AppleScript的正确按钮。我开始学习VIM和希望能够切换大写锁定大写锁定和Ctrl 之间的关键。我已标记,我需要完成的步骤。
I can't seem to figure out how to select the correct buttons with Applescript. I am starting to learn vim and want to be able to toggle the Caps Lock Key between Caps Lock and Ctrl. I have marked the steps which I need to complete.
我发现(<一个href=\"http://stackoverflow.com/questions/16093042/applescript-script-to-switch-caps-lock-key-to-control\">this帖子),但它似乎有点哈克。也许这是它应该是的方式,但它显示了系统preF。窗口的每次我用它,不像(这个code )的时间切换的< STRONG> FN 键并无缝地工作。
I found (this post) but it seems to be a little hacky. Maybe it's the way it supposed to be but it shows the system pref. window every time I use it, unlike (this code) that toggles the fn key and works seemlessly.
任何人都可以提供一些建议?
Could anyone offer some advice?
这里是我的code:
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
这里是修改键截图:
推荐答案
这将切换键(你必须改变德国的标签):
This toggles the keys (you have to change the german labels):
tell application "System Events"
tell application "System Preferences"
reveal anchor "keyboardTab" of pane "com.apple.preference.keyboard"
end tell
tell window 1 of application process "System Preferences"
click button "Sondertasten …" of tab group 1
tell sheet 1
tell pop up button "Feststelltaste (⇪):"
set state to value
click
delay 0.2
if "Feststelltaste" is in state then
click menu item "⌃ ctrl-Taste" of menu 1
else
click menu item "⇪ Feststelltaste" of menu 1
end if
delay 0.2
end tell
click button "OK"
end tell
end tell
end tell
if application "System Preferences" is running then
tell application "System Preferences" to quit
end if
但作为富写道,图形用户界面的脚本应该是最后的解决方案。尤其是在小牛是真烦人,因为你(如果你改变你的脚本一次)启用辅助设备的访问为每一个应用程序。
But as foo wrote, GUI-Scripts should be the last solution. Especially in Mavericks it's really annoying because you have to enable access for assistive devices for every single app (and again if you change your script).
这篇关于如何使用AppleScript的切换Caps Lock键是Ctrl键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!