该keystroke
命令只能用于插入在当前键盘布局上可以找到的字符,并且较长的文本字符串会有明显的延迟。您还可以直接插入文本:
该方法也不是真的可用。在10.7和10.8中有一个错误,其中直到您将鼠标悬停在服务菜单上时,Automator服务的快捷方式才总是起作用。
我已使用FastScripts将此脚本分配给F3:
try
set old to the clipboard as record
end try
try
tell application "System Events"
key code 123 using {option down, shift down}
keystroke "c" using command down
end tell
delay 0.05
set input to the clipboard
read POSIX file "/Users/lauri/Notes/snippets.txt" as «class utf8» using delimiter linefeed
repeat with p in result
considering case
if p starts with (input & " ") then
set the clipboard to text ((offset of space in p) + 1) thru -1 of p
tell application "System Events" to keystroke "v" using command down
delay 0.05
exit repeat
end if
end considering
end repeat
end try
try
set the clipboard to old
end try
snippets.txt看起来像这样:
m name@example.com
cmd ⌘
另一种选择是使用DefaultKeyBinding.dict。这将使⌥M或⌥X和m插入电子邮件地址:
{
"~m" = (insertText:, "name@example.com");
"~x" = {
"m" = ("insertText:", "name@example.com");
};
}
您也可以在按住键时将自定义文本添加到显示的弹出窗口中。看到这个问题。