applescript - 在自动机中使用苹果脚本执行键盘快捷键

标签 applescript

我第一次在自动机中使用苹果脚本。我希望脚本在之前启动的应用程序中执行键盘快捷键。

on run
activate application "MacCaption"
tell application "MacCaption"
    keystroke "x" using command down

end tell

我收到了预期行尾的语法错误,但在使用的单词上找到了标识符。

最佳答案

你的问题是 keystroke必须通过系统事件。任何一个:

tell app "System Events"
    keystroke "x" using command down
end tell

或者
tell app "System Events"
    tell process "MacCaption"
        keystroke "x" using command down
    end tell
end tell

没有真正的区别,但您需要系统事件。

关于applescript - 在自动机中使用苹果脚本执行键盘快捷键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14247720/

相关文章:

javascript - 如何从不同位置自动下载多个 PDF 文件(AppleScript 或 JavaScript)

macos - 绕过图形管理员密码打开 OSX 应用程序命令行解决方案

objective-c - 如何从应用程序 B 访问应用程序 A 的功能

cocoa - 如何收听所有 Apple 事件?

AppleScript + Quicktime : Start and stop a movie recording and export it to disk

applescript - 使用 AppleScript 单击应用程序菜单栏项目

swift - AppleScript(或 swift)增加时间

cocoa - 在 SDEF 中声明各种 <accessor style> 标签有什么作用?

objective-c - Cocoa/Objective-C 获取一个 HFS 路径(路径 :to:desktop) from a posix path (path/to/desktop)

shell - 在 Finder 中选择的文件上执行 shell 命令