如何使用“考虑案例”在 Applescript 中处理 Microsoft Word 时

发布于 2025-01-04 19:18:14 字数 433 浏览 1 评论 0原文

以下 Applescript 代码无法编译;编译器突出显示“case”并说:“语法错误:预期的应用程序常量或考虑因素,但发现了属性”。我猜 casetell 应用程序“Microsoft Word” 的上下文中具有特殊含义。我怎样才能很好地解决这个问题?

tell application "Microsoft Word"
    set c to content of character 1 of selection as string
    considering case
        if (c is "a") then
            set content of text object of selection to "A"
        end if
    end considering
end tell

The following Applescript code does not compile; the compiler highlights “case” and says: “Syntax Error: expected application constant or consideration but found property”. I guess case has a special meaning in the context of tell application "Microsoft Word". How can I work around that nicely?

tell application "Microsoft Word"
    set c to content of character 1 of selection as string
    considering case
        if (c is "a") then
            set content of text object of selection to "A"
        end if
    end considering
end tell

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

噩梦成真你也成魔 2025-01-11 19:18:14

我要做的就是尝试将 considering 块移到外部,以便它包含其他所有内容。

看来 case 是 Microsoft Word 的保留字,因此在 tell 块内的不同上下文中使用该词只会让编译器感到困惑,因此会出现语法错误正在得到。

What I would do is try moving the considering block to the outside so that it encompasses everything else.

It appears that case is a reserved word for Microsoft Word, and so using that word in a different context while inside the tell block just confuses the compiler, hence the syntax error you are getting.

零度℉ 2025-01-11 19:18:14

fireshadow52 是对的...

considering case
tell application "Microsoft Word"
    set c to content of character 1 of selection as string
    if (c is "a") then
        set content of text object of selection to "A"
    end if
end tell
end considering

fireshadow52 is right ...

considering case
tell application "Microsoft Word"
    set c to content of character 1 of selection as string
    if (c is "a") then
        set content of text object of selection to "A"
    end if
end tell
end considering
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文