Applescript逼真的按键
是否可以使用Applescript以随机速度快速高效地键入文本?我有以下脚本: 在运行{input,parameters}时:Applescript逼真的按键,applescript,keystroke,Applescript,Keystroke,是否可以使用Applescript以随机速度快速高效地键入文本?我有以下脚本: 在运行{input,parameters}时: tell application "System Events" keystroke "H" delay 0.2 keystroke "i" delay 0.2 keystroke " " delay 0.2 keystroke "t" delay 0.2 keystroke "h" del
tell application "System Events"
keystroke "H"
delay 0.2
keystroke "i"
delay 0.2
keystroke " "
delay 0.2
keystroke "t"
delay 0.2
keystroke "h"
delay 0.2
keystroke "e"
delay 0.2
keystroke "r"
delay 0.2
keystroke "e"
delay 0.2
keystroke "!"
delay 0.1
key code 36
delay 0.5
keystroke "H"
delay 0.2
keystroke "o"
delay 0.1
keystroke "w"
delay 0.2
keystroke " "
delay 0.1
keystroke "a"
delay 0.2
keystroke "r"
delay 0.1
keystroke "e"
delay 0.2
keystroke " "
delay 0.1
keystroke "y"
delay 0.2
keystroke "o"
delay 0.2
keystroke "u"
delay 0.1
keystroke "?"
delay 0.2
key code 36
delay 1.0
keystroke "W"
delay 0.2
keystroke "h"
delay 0.2
keystroke "e"
delay 0.1
keystroke "r"
delay 0.2
keystroke "e"
delay 0.2
keystroke " "
delay 0.1
keystroke "d"
delay 0.2
keystroke "o"
delay 0.2
keystroke " "
delay 0.2
keystroke "y"
delay 0.2
keystroke "o"
delay 0.1
keystroke "u"
delay 0.2
keystroke " "
delay 0.1
keystroke "w"
delay 0.2
keystroke "a"
delay 0.1
keystroke "n"
delay 0.2
keystroke "t"
delay 0.2
keystroke " "
delay 0.1
keystroke "t"
delay 0.3
keystroke "o"
delay 0.2
keystroke " "
delay 0.1
keystroke "b"
delay 0.2
keystroke "e"
delay 0.2
keystroke "g"
delay 0.1
keystroke "i"
delay 0.2
keystroke "n"
delay 0.1
keystroke "?"
end tell
return input
end run
基本上,我希望在一次击键(或类似命令)中键入所有单词(至少1行),然后在每个键之间使用随机延迟,如下面所示。可能吗
delay (random number from 0.05 to 1.0)
解决它-
您只需要创建一个文件(我使用的是.txt文件而不是.js文件),指定位置&hey presto
以下是我对随机文本速度的调整:
set fc to read POSIX file "/test/testdoc.txt" as «class utf8»
set the text item delimiters to (ASCII character 10)
set mylines to text items in fc
repeat with currentline in mylines
write_string(currentline)
end repeat
on write_string(the_string)
tell application "System Events"
tell application "textedit" to activate
delay 10
repeat with the_character in the_string
keystroke the_character
delay (random number from 0.05 to 0.25)
end repeat
key code 36
key code 123 using command down
end tell
end write_string
如果您不介意没有退货,请使用以下方法:
delay 3
set new_array to "h, i, , t, h, e, r, e, !, , h, o, w, , a, r, e, , y, o, u, ?, , w, h, e, r, e, , d, o, , y, o, u, , w, a, n, t, , t, o, , b, e, g, i, n, ?"
set AppleScript's text item delimiters to ", "
set the list_items to every text item of the new_array
set a to list_items
set b to count of list_items
set c to 0
tell application "System Events"
repeat b times
set c to c + 1
delay (random number from 0.05 to 0.3)
keystroke item c of a
end repeat
end tell
delay 3
set a to "h, i, , t, h, e, r, e, !"
set b to "h, o, w, , a, r, e, , y, o, u, ?"
set c to "w, h, e, r, e, , d, o, , y, o, u, , w, a, n, t, , t, o, , b, e, g, i, n, ?"
set AppleScript's text item delimiters to ", "
set the list_items to every text item of the a
set d to list_items
set e to count of list_items
set f to 0
set AppleScript's text item delimiters to ", "
set the m to every text item of the b
set g to m
set h to count of m
set i to 0
set AppleScript's text item delimiters to ", "
set the n to every text item of the c
set j to n
set k to count of n
set l to 0
tell application "System Events"
repeat e times
set f to f + 1
delay (random number from 0.05 to 0.3)
keystroke item f of d
end repeat
key code 36
repeat h times
set i to i + 1
delay (random number from 0.05 to 0.3)
keystroke item i of g
end repeat
key code 36
repeat k times
set l to l + 1
delay (random number from 0.05 to 0.3)
keystroke item l of j
end repeat
end tell
但如果您想要退货,请使用以下方法:
delay 3
set new_array to "h, i, , t, h, e, r, e, !, , h, o, w, , a, r, e, , y, o, u, ?, , w, h, e, r, e, , d, o, , y, o, u, , w, a, n, t, , t, o, , b, e, g, i, n, ?"
set AppleScript's text item delimiters to ", "
set the list_items to every text item of the new_array
set a to list_items
set b to count of list_items
set c to 0
tell application "System Events"
repeat b times
set c to c + 1
delay (random number from 0.05 to 0.3)
keystroke item c of a
end repeat
end tell
delay 3
set a to "h, i, , t, h, e, r, e, !"
set b to "h, o, w, , a, r, e, , y, o, u, ?"
set c to "w, h, e, r, e, , d, o, , y, o, u, , w, a, n, t, , t, o, , b, e, g, i, n, ?"
set AppleScript's text item delimiters to ", "
set the list_items to every text item of the a
set d to list_items
set e to count of list_items
set f to 0
set AppleScript's text item delimiters to ", "
set the m to every text item of the b
set g to m
set h to count of m
set i to 0
set AppleScript's text item delimiters to ", "
set the n to every text item of the c
set j to n
set k to count of n
set l to 0
tell application "System Events"
repeat e times
set f to f + 1
delay (random number from 0.05 to 0.3)
keystroke item f of d
end repeat
key code 36
repeat h times
set i to i + 1
delay (random number from 0.05 to 0.3)
keystroke item i of g
end repeat
key code 36
repeat k times
set l to l + 1
delay (random number from 0.05 to 0.3)
keystroke item l of j
end repeat
end tell