当我使用 AppleScript 从 TextExpander 在 BBEdit 中设置文本时,为什么系统会发出蜂鸣声?
我编写了一个 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
当我键入 [ 字符时,它会被触发,如果选择文本,它将把文本包装在 [ 和 ]< 中/strong> 但如果没有选择任何文本,那么它应该像平常一样简单地输入 [ 字符。
无论运行方式如何,它都可以完美运行,但如果从 TextExpander 运行,则遵循“else”路径(将选择的文本设置为“[”
),系统会发出蜂鸣声。我不确定 BBEdit 或 TextExpander 是否会发出蜂鸣声,但如果我完全删除“else”部分或者它在选择文本(“if”路径)的情况下运行,则不会发出蜂鸣声。
I've written an AppleScript that is designed to fire when TextExpander notices a keystroke. It works fine when run from the AppleScript Editor but under certain conditions it also beeps when run from TextExpander.
Here's the script:
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
It's set to fire when I type the [ character, with the idea that if text is selected it will wrap the text in [ and ] but if no text is selected then it should simply type the [ character as normal.
It works perfectly however it's run, but if run from TextExpander and the "else" path is follow (set text of selection to "["
) the system beeps. I'm not sure if BBEdit or TextExpander is generating the beep, but there's no beep if I completely remove the "else" section or if it runs with text selected (the "if" path).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Smile Software(TextExpander 的制造商)的人员为我找到了一个完美可行的解决方案。
而不是
(必须在选择后选择插入点才能取消选择[),这完美地工作:
无论如何,这是一个更好的主意。
The folks at Smile Software (makers of TextExpander) found a perfectly workable solution for me.
Instead of
(which had to be followed by
select insertion point after selection
in order to deselect the [ anyway), this works perfectly:which is a better idea anyway.