【问题标题】:Can't send keystrokes from Terminal to app using osascript in MacOS无法在 MacOS 中使用 osascript 将击键从终端发送到应用程序
【发布时间】:2021-10-13 11:39:12
【问题描述】:

我打开了 TextEdit。 我想在 TextEdit 中输入“hello”,但不是通过自己输入,而是使用终端中的命令。

我试过了:

osascript -e 'tell application "TextEdit" to keystroke "hello"'

但它给出了以下错误:

31:48: execution error: TextEdit got an error: Can’t get keystroke "hello". (-1728)

我做错了什么?

【问题讨论】:

  • 错误的应用程序 - 系统事件 是执行击键的应用程序(查看应用程序的脚本字典)。

标签: terminal keystroke osascript


【解决方案1】:

red_menace 是对的,这行得通:

osascript -e 'activate application "TextEdit"'; osascript -e 'tell application "System Events" to keystroke "hello"' 

【讨论】:

    猜你喜欢
    • 2017-02-13
    • 2013-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-26
    • 2011-01-07
    • 1970-01-01
    相关资源
    最近更新 更多