Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 使Applescript编辑器记录按下的键_Macos_Applescript - Fatal编程技术网

Macos 使Applescript编辑器记录按下的键

Macos 使Applescript编辑器记录按下的键,macos,applescript,Macos,Applescript,我对applescript相当陌生(我知道一两件事),但我不能用它来做更高级的事情。好的,问题是我需要一个脚本来记录/监控我按下的键。但不是直接在输入框中键入,如以下脚本: display dialog "" default answer "" buttons {"OK"} default button 1 set answer to text returned of the result display dialog answer buttons {"OK"} default button 1

我对applescript相当陌生(我知道一两件事),但我不能用它来做更高级的事情。好的,问题是我需要一个脚本来记录/监控我按下的键。但不是直接在输入框中键入,如以下脚本:

display dialog "" default answer "" buttons {"OK"} default button 1
set answer to text returned of the result
display dialog answer buttons {"OK"} default button 1

例如,如果我在浏览器中键入“www.google.com”,然后返回applescript,它将记录“www.google.com”,感谢您为创建此脚本提供的任何帮助

如果您只想在浏览器中键入URL(使用Safari),只需执行以下操作:

tell application "Safari" to get URL of first document
但是,我相信你想得到网页上特定输入字段中的内容,对吗?然后你可以这样做: 1) 将“qwerty”写入您感兴趣阅读的输入字段。 2) 在AppleScript编辑器上运行此脚本:

tell application "Safari"
    tell first document
        set numberOfInputFields to do JavaScript "document.getElementsByTagName(\"input\").length;"
        repeat with i from 0 to numberOfInputFields - 1
            set inputValueScript to "document.getElementsByTagName(\"input\")[" & i & "].value"
            set inputValue to (do JavaScript inputValueScript)
            if inputValue is equal to "qwerty" then
                display alert "Index of input field: " & i
                return
            end if
        end repeat
    end tell
end tell
然后您将获得输入字段的索引。将该数字输入此脚本并点击run:

tell application "Safari"
    tell first document
        set indexOfInputField to "place-the-number-here"
        set inputValueScript to "document.getElementsByTagName(\"input\")[" & indexOfInputField & "].value"
        set inputValue to (do JavaScript inputValueScript)
    end tell
    display alert "Text in input field " & indexOfInputField & ": " & inputValue
end tell

您将得到输入到该字段中的内容(“qwerty”,如果您没有从上一个脚本更改它)。如您所见,这些脚本使用JavaScript从web页面读取。如果我的答案不是您想要的,您可以尝试使用其他JavaScript命令,例如。

AppleScript无法执行that@vadian好的,但是你确定绝对没有办法做到我上面提到的。或者有什么东西可以接近它吗?香草AppleScript没有,因为AS基本上是在一个线程上运行的。要监视键盘事件,至少需要第二个线程以避免阻塞UI。也许AppleScriptObjC或与可可粉结合使用可以做到这一点。汉克斯,你们真是太棒了。但愿我能理解所有这些编码/脚本的一半含义。:)但我希望有一天我能到达那里。。。