Реалистичное нажатие клавиши Applescript

Можно ли использовать Applescript для быстрого и эффективного набора текста с произвольной скоростью? У меня есть следующий скрипт:

При запуске {вход, параметры}:

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)

2 ответа

Если вы не возражаете против возврата, используйте это:

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

Решил это - http://christianheilmann.com/2014/01/09/autmating-typing-in-screencasts-with-applescript-or-how-to-look-like-a-hollywood-hacker/

Вам просто нужно создать файл (я использовал файл.txt, а не файл.js), указать местоположение и привет.

Вот мой твик с рандомизированной скоростью текста:

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
Другие вопросы по тегам