2013-04-18 59 views
1

我试图找到解决方案,因为我使用Vim,大部分时间我需要将大写锁定分配给Ctrl。有时候,我想让Caps Lock正常工作。我认为Apple脚本非常棒,因为它可以分配给LaunchBar操作。AppleScript:将大写锁定键切换到脚本的脚本

我将与我结束了(通过GUI脚本),但有兴趣,如果有人知道的方式干扰性较低的解决方案解决方案回答...

回答

0

您可以使用PCKeyboardHack将大写锁定更改为F19。然后,它保存为private.xml

<?xml version="1.0"?> 
<root> 
<item> 
<name>caps1</name> 
<identifier>caps1</identifier> 
<autogen>__KeyToKey__ KeyCode::F19, KeyCode::CAPSLOCK</autogen> 
</item> 
<item> 
<name>caps2</name> 
<identifier>caps2</identifier> 
<autogen>__KeyToKey__ KeyCode::F19, KeyCode::CONTROL_L</autogen> 
</item> 
</root> 

,并使用该脚本来切换设置:

k=/Applications/KeyRemap4MacBook.app/Contents/Applications/KeyRemap4MacBook_cli.app/Contents/MacOS/KeyRemap4MacBook_cli 
if $k changed | grep -q ^caps1=; then 
    $k disable caps1 
    $k enable caps2 
else 
    $k enable caps1 
    $k disable caps2 
fi 

这将是容易,只需指定另一个组合键,大写锁定,但:

<autogen>__KeyOverlaidModifier__ KeyCode::CONTROL_L, ModifierFlag::FN, KeyCode::CONTROL_L, ModifierFlag::FN, KeyCode::CAPSLOCK</autogen>

这会在按键关闭时触发,因此您必须在fn之前按下控制键才能使用组合键,如fn + control + down:

<autogen>__KeyToKey__ KeyCode::CONTROL_L, ModifierFlag::FN, KeyCode::CAPSLOCK</autogen>

1

这是我目前使用的脚本:

tell application "System Preferences" 
    activate 
    set current pane to pane "com.apple.preference.keyboard" 
end tell 

tell application "System Events" 
tell application process "System Preferences" 
    get properties 

    click button "Modifier Keys…" of tab group 1 of window "Keyboard" 
    tell sheet 1 of window "Keyboard" 
    click pop up button 4 
    set capsLockCurrentlyOn to (value of attribute "AXMenuItemMarkChar" of menu item 1 of menu 1 of pop up button 4 as string) ≠ "" 
    --display dialog "Caps Lock On: " & capsLockCurrentlyOn 
    if capsLockCurrentlyOn is true then 
     --tell me to beep 3 
     click menu item 2 of menu 1 of pop up button 4 
    else 
     --tell me to beep 2 
     click menu item 1 of menu 1 of pop up button 4 
    end if 
    click button "OK" 
    end tell 
end tell 
tell application "System Preferences" to quit 
end tell 
+0

你有没有让它正常工作?我无法得到(点击弹出按钮4的菜单1的菜单项1)工作。它只是保持选择CTRL选项。 –

+0

@AlexCory我结束了使用KeyRemapMacBook。只有我很少使用它,因此我甚至不记得快捷方式!嗯... – Dionysis