最近在百度知道上给一个童鞋写了一个快速切换触发角的 AppleScript,来实现在游戏启动前运行给所有触发角添加一个修饰键(如 Command),结果发现需求的人还是挺多的。 觉得有必要写一篇简单的教程。
其实原理非常简单,就是直接用终端的 defaults
来修改配置文件,这里的配置文件就是:“com.apple.dock”。
当然 AppleScript 中本身具有修改 plist 文件的方法,但是这个不熟,不如直接使用终端命令来的方便。
对于每个触发角都有两个属性,分别是功能和修饰键,在 “com.apple.dock” 中表现为:wvous-pos-corner
和 wvous-pos-modifier
,其中 pos 是要替换的,可以替换成 bl
, tl
, br
, tr
四个,我认为其中 b
表示 bottom,t
表示 top,r
表示 right,l
表示 left。
下面就是代码,这里做的是无修饰键和⌘键之间的切换,
如果需要切换其他的可以直接在下面代码中修改 adjustModifier
的值。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
* Author: fate_stigma@hotmal.com | |
* Date: Nov. 21, 2014 | |
* Usage: switch your Hot Corner Modifier | |
*) set nullModifier to "0" set commandModifier to "1048576" set optionModifier to "524288" set controlModifier to "262144" set shiftModifier to "131072" set commandOptionModifier to "1572864" set commandControlModifier to "1310720" set commandShiftModifier to "1179648" set optionControlModifier to "786432" set optionShiftModifier to "655360" set controlShiftModifier to "393216" set commandOptionControlModifier to "1835008" set commandOptionShiftModifier to "1703936" set OptionControlShiftModifier to "917504" set commandOptionControlShiftModifier to "1966080" set defaultModifier to nullModifier -- 默认无修饰键 set adjustModifier to commandModifier -- 这里替换修饰键为+⌘ -- 获取当前修饰键状态 set presentState to do shell script "defaults read com.apple.dock wvous-tl-modifier" -- 修饰键反转 if presentState is equal to defaultModifier then set setState to adjustModifier else set setState to defaultModifier end if do shell script " | |
defaults write com.apple.dock wvous-tl-modifier -int " & setState & "; | |
defaults write com.apple.dock wvous-tr-modifier -int " & setState & "; | |
defaults write com.apple.dock wvous-bl-modifier -int " & setState & "; | |
defaults write com.apple.dock wvous-br-modifier -int " & setState & "; | |
killall Dock" |
附录
修饰键和键码对照
Modifier | Keycode |
---|---|
null | 0 |
⌘ | 1048576 |
⌥ | 524288 |
⌃ | 262144 |
⇧ | 131072 |
⌘⌥ | 1572864 |
⌘⌃ | 1310720 |
⌘⇧ | 1179648 |
⌥⌃ | 786432 |
⌥⇧ | 655360 |
⌃⇧ | 393216 |
⌘⌥⌃ | 1835008 |
⌘⌥⇧ | 1703936 |
⌥⌃⇧ | 917504 |
⌘⌥⌃⇧ | 1966080 |
触发角功能对应码
Corner | Code |
---|---|
null | 1 |
Mission Control | 2 |
Application Windows | 3 |
Desktop | 4 |
Dashboard | 7 |
Notification Center | 12 |
Launchpad | 11 |
Start Screen Saver | 5 |
Disable Screen Saver | 6 |
Put Display to Sleep | 10 |