让 Applescript 编辑器记录按下的键
Make Applescript Editor record keys that were press
我对 applescript 还很陌生(我对它了解一两件事),但我无法用它做一些改进。好吧,问题是我需要一个脚本,它将 record/monitor 我按下的键。但不能像下面的脚本那样直接在输入框中输入:
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
然后您将获得输入字段的索引。将该数字放入此脚本并点击 运行:
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 从网页中读取。如果我的回答不是您想要的,您可以尝试其他 JavaScript 命令,例如 found here。
我对 applescript 还很陌生(我对它了解一两件事),但我无法用它做一些改进。好吧,问题是我需要一个脚本,它将 record/monitor 我按下的键。但不能像下面的脚本那样直接在输入框中输入:
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
然后您将获得输入字段的索引。将该数字放入此脚本并点击 运行:
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 从网页中读取。如果我的回答不是您想要的,您可以尝试其他 JavaScript 命令,例如 found here。