当我使用 AppleScript 从 TextExpander 在 BBEdit 中设置文本时,为什么系统会发出蜂鸣声?

发布于 2024-12-08 03:07:35 字数 697 浏览 1 评论 0原文

我编写了一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉生梦死 2024-12-15 03:07:35

Smile Software(TextExpander 的制造商)的人员为我找到了一个完美可行的解决方案。

而不是

set text of selection to "["

(必须在选择后选择插入点才能取消选择[),这完美地工作:

return "["

无论如何,这是一个更好的主意。

The folks at Smile Software (makers of TextExpander) found a perfectly workable solution for me.

Instead of

set text of selection to "["

(which had to be followed by select insertion point after selection in order to deselect the [ anyway), this works perfectly:

return "["

which is a better idea anyway.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文