【问题标题】:execute a keyboard shortcut using apple script in automator在automator中使用苹果脚本执行键盘快捷键
【发布时间】:2021-11-10 00:11:52
【问题描述】:

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

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

end tell

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

【问题讨论】:

    标签: applescript


    【解决方案1】:

    您的问题是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
    

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

    【讨论】:

      【解决方案2】:

      试试:

      tell application "System Events" to keystroke "x" using command down
      

      【讨论】:

        猜你喜欢
        • 2017-09-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-31
        • 2011-05-06
        • 2012-06-26
        • 1970-01-01
        相关资源
        最近更新 更多