我编写了一个 AppleScript,旨在在 TextExpander 注意到击键时触发。从 AppleScript 编辑器运行时它工作正常,但在某些情况下,从 TextExpander 运行时它也会发出哔哔声。
这是脚本:
tell front window of application "BBEdit"
if (length of selection) is not 0 then
add prefix and suffix of selection prefix "[" suffix "]"
else
set text of selection to "["
end if
end tell
当我输入 [ 字符时,它被设置为触发,如果选择文本,它会将文本包裹在 [ 和 ] 但如果没有选择文本,那么它应该简单地输入 [ 字符正常.
无论它运行如何,它都可以完美运行,但是如果从 TextExpander 运行并且遵循“else”路径(
set text of selection to "["
),则系统会发出哔哔声。我不确定 BBEdit 或 TextExpander 是否正在生成蜂鸣声,但是如果我完全删除“else”部分或者它在选择文本(“if”路径)的情况下运行,则不会发出蜂鸣声。 最佳答案
Smile Software(TextExpander 的制造商)的人为我找到了一个完美可行的解决方案。
代替
set text of selection to "["
(必须跟上
select insertion point after selection
才能取消选择 [ 无论如何),这完美地工作:return "["
无论如何,这是一个更好的主意。
关于applescript - 当我使用 AppleScript 从 TextExpander 在 BBEdit 中设置文本时,为什么系统会发出哔哔声?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7644448/