Rut*_*hie 25 keyboard-shortcuts hotkeys copy-paste macos
我有一个在多个应用程序中经常使用的文本短语(实际上是几个阶段)。我想创建一个键盘快捷键或热键,将这个文本短语粘贴到我将光标放在文本输入字段(Apple Mail、Microsoft Word、TextEdit、TextWrangler、浏览器窗口等)中的任何位置,而不是不断地复制和从便签粘贴。
我宁愿不必购买任何应用程序(似乎 Keyboard Maestro 具有此功能,但仅为此支付 36 美元似乎很愚蠢),尽管免费应用程序也可以。尝试在“系统偏好设置”>“键盘”>“键盘快捷键”下查看,但没有明显的解决方案,而且我发现的所有 AppleScript 似乎都无法正确翻译。我在此论坛上为 Windows 用户(如 AutoHotKey)找到了针对此问题的其他解决方案,但没有为 Mac 用户找到解决方案。
slh*_*hck 22
使用 AppleScript 键入文本的最简单方法是运行:
tell application "System Events" to keystroke "foo bar"
Run Code Online (Sandbox Code Playgroud)
您可以通过在 Automator 中创建新的快速操作(以前称为Service)来使用键盘快捷键触发此操作。将其设置为接收No Input,然后将Run AppleScript从左侧窗格拖到右侧。
它应该是这样的:

保存它,然后在System Preferences » Keyboard » Keyboard Shortcuts下为该服务分配一个键盘快捷键。

Kal*_*Kal 10
到 2022 年,无需任何脚本或第三方产品即可实现此目的的简单方法是使用快捷方式应用程序。
+以创建新快捷方式。Text动作从“动作库”面板拖动到编辑器。Stop and Output操作到编辑器。Use as Quick Action选项。Add Keyboard Shortcut按钮,然后输入所需的组合键。您的新快捷方式现在应该可以通过多种方式使用。在文本文档或文本字段中:
该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
Run Code Online (Sandbox Code Playgroud)
snippets.txt 看起来像这样:
m name@example.com
cmd ?
Run Code Online (Sandbox Code Playgroud)
另一种选择是使用DefaultKeyBinding.dict。这将使 ?M 或 ?X 和 m 插入一个电子邮件地址:
{
"~m" = (insertText:, "name@example.com");
"~x" = {
"m" = ("insertText:", "name@example.com");
};
}
Run Code Online (Sandbox Code Playgroud)
您还可以向按住键时显示的弹出窗口添加自定义文本。看到这个问题。
小智 6
只需单击:系统偏好设置、键盘、文本,然后输入快捷方式和短语
| 归档时间: |
|
| 查看次数: |
61705 次 |
| 最近记录: |