【问题标题】:Why is the system beeping when I use AppleScript to set text in BBEdit from TextExpander?为什么我使用 AppleScript 从 TextExpander 在 BBEdit 中设置文本时系统会发出哔哔声?
【发布时间】:2011-10-04 07:16:49
【问题描述】:

我编写了一个 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”路径),则不会发出哔声。

【问题讨论】:

    标签: applescript bbedit


    【解决方案1】:

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

    代替

    set text of selection to "["
    

    (必须后跟select insertion point after selection 才能取消选择 [),这非常有效:

    return "["
    

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

    【讨论】:

      猜你喜欢
      • 2012-07-16
      • 1970-01-01
      • 2021-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多