使用 applescript 粘贴到 Microsoft Word

发布于 2024-10-31 19:55:02 字数 320 浏览 1 评论 0原文

我正在尝试制作一个简单的 applescript,其执行以下操作:

切换到 Microsoft Word 类型 * 按粘贴(命令 v) 按回车键

我想出了这个,但它行不通......有什么想法吗?

tell application "System Events"
    tell application process "Microsoft Word" to activate
        keycode(42)
        keycode(118)
        keycode(3)
    end tell
end tell

I'm trying to make a simple applescript which doesn the following:

Switch to Microsoft Word
type *
press paste (command v)
press return

I came up with this but it won't work... Any ideas why??

tell application "System Events"
    tell application process "Microsoft Word" to activate
        keycode(42)
        keycode(118)
        keycode(3)
    end tell
end tell

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

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

发布评论

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

评论(2

倦话 2024-11-07 19:55:02

您以错误的方式使用关键代码并且您的告诉块不正确尝试这个

tell application "Microsoft Word"
    activate
    tell application "System Events"
        tell application process "Microsoft Word"
            key code 42
            key code 118
            key code 3
        end tell
    end tell
end tell

your using key code in the wrong manner and your tell blocks are not correct try this

tell application "Microsoft Word"
    activate
    tell application "System Events"
        tell application process "Microsoft Word"
            key code 42
            key code 118
            key code 3
        end tell
    end tell
end tell
关于从前 2024-11-07 19:55:02

一般来说,如果您尽可能使用文本而不是键码,您的代码会更容易编写且更具可读性。

tell application "Microsoft Word"
    activate
end tell

tell application "System Events"
    tell application process "Microsoft Word"
        keystroke "*"
        keystroke "v" using command down
        keystroke return
    end tell
end tell

In general your code is easier to write and much more readable if you use text wherever possible rather than keycodes.

tell application "Microsoft Word"
    activate
end tell

tell application "System Events"
    tell application process "Microsoft Word"
        keystroke "*"
        keystroke "v" using command down
        keystroke return
    end tell
end tell
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文