【问题标题】:Applescript - Keystroke text from variableApplescript - 来自变量的击键文本
【发布时间】:2017-09-10 13:31:00
【问题描述】:

我有一个包含一些文本的文件。我能够将此文本读入变量。我想使用keystroke 命令将此文本发送到应用程序。当包含keystroke 的行运行时,它会生成一个对话框,其中包含错误“语法错误 - 无法获得击键“..文件内容..”'

on run {input, parameters}
    set inputfile to "/path/to/textfile.txt"
    set fileText to read inputfile
    keystroke fileText
end run

如何将文件内容作为击键发送?

【问题讨论】:

    标签: applescript


    【解决方案1】:

    keystroke 命令系统事件流程套件的一部分,因此在使用keystroke 命令时,它必须来自系统事件

    例子:

    tell application "System Events" to keystroke fileText
    

    不过,话虽如此,您需要先将焦点设置在您希望输入的位置,例如:

    tell application "TextEdit" to activate
    delay 1
    

    例如,您的代码将是:

    on run {input, parameters}
        set inputfile to "/path/to/textfile.txt"
        set fileText to read inputfile
        tell application "TextEdit" to activate
        delay 1
        tell application "System Events" to keystroke fileText
    end run
    

    【讨论】:

    • 谢谢!我错过了脚本的“系统事件”部分。对此还是陌生的。
    猜你喜欢
    • 2016-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-17
    • 2014-06-25
    • 1970-01-01
    相关资源
    最近更新 更多