Applescript Realistic Keystroke - applescript

Is it possible to use Applescript to type text at a randomised speed quickly & efficiently? I have the following script:
On run {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"
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
I basically, want to type all of the words (for 1 line at least) in one keystroke (or similar command), and then use a random delay such as the below between each key. Is it possible?
delay (random number from 0.05 to 1.0)

Solved it - http://christianheilmann.com/2014/01/09/autmating-typing-in-screencasts-with-applescript-or-how-to-look-like-a-hollywood-hacker/
You just need to create a file (I used a .txt file rather than a .js file), specify the location & hey presto.
Heres my tweak with randomised text speed:
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

If you do not mind that there are no returns then use this:
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
But if you want the returns then use this:
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

Related

Given multiple lists of numbers find the sum that is the closest to a specific number

I'm trying to solve a problem and i'm not really sure how to do it.
Basically, the input is composed of a set of lists with numbers and a number which look like this:
Input Data
A = [0,3,6]
B = [0.5,0.63,1]
C = [0.12,0.3,0.7]
D = [0.12,0.3,0.7]
E = [0.5,0.25,0.1]
F = [0.5,0.25,0.1]
Number = 8.3
I need to find all possible combinations that sumed up gives a value that is 8.3 or close to 8.3 but also there are a few conditions:
Values from C list needs to be smaller or equal than values from D list
Also values from E list needs to be smaller or equal than values from F list
From each list i can choose only one number at a time
For example: 0 + 0.5 + 0.3 + 0.12 + 0.5 + 0.5 -> is wrong because 0.3 is bigger than 0.12
But, 0 + 0.5 + 0.3 + 0.7 + 0.5 + 0.5 -> is correct because the value from C list(0.3) is bigger than 0.7 and value from E list(0.5) is equal to F list(0.5)

Generating a Heatmap Table in gnuplot

I am trying to generate a Heatmap with gnuplot but with a two distinct information for each entry in the heatmap. While heatmap shows the value as color, I want each block in the heatmap to show textual information as well.
The following script creates half of what I have in mind:
set term postscript eps color solid
set output '1.eps'
set title "Heat Map generated from a file containing Z values only"
unset key
set tic scale 0
set border linewidth 2
set palette rgbformula -7,2,-3
unset cbtics
unset colorbox
unset xtics
set x2tics ("A" 0, "B" 1, "C" 2, "D" 3, "E" 4)
set ytics ("N0" 0, "N1" 1, "N2" 2, "N3" 3, "N4" 4)
set style line 102 lc rgb'#101010' lt 0 lw 4
set grid front ls 102
set datafile separator ","
plot 'matrix.txt' matrix with image, "" matrix using 1:2:(sprintf('%.2f', $3)) with labels font ',12' offset 0,1.2
set datafile separator
The data file, matrix.txt contains the following information:
7 B, 5 B, 4 D, 3 B, 1 D
2 B, 2 A, 2 D, 0 C, 0 A
3 B, 0 A, 0 E, 0 E, 1 C
4 C, 0 A, 0 B, 0 E, 2 C
5 D, 0 A, 1 A, 2 A, 4 A
The following graph can be resulted from the script:
I want to be able to add the textual information in each entry as second part of the matrix entries (under the grid line).
I was wondering if you guys have any suggestions on how.
Thanks
Seems like you cannot use stringcolumn (or strcol) together with matrix to get the complete string contained in the respective matrix elements. As workaround you must iterate over all columns and plot each of them separately with labels:
set title "Heat Map generated from a file containing Z values only"
unset key
set tic scale 0
set border linewidth 2
set palette rgbformula -7,2,-3
unset cbtics
unset colorbox
unset xtics
set x2tics ("A" 0, "B" 1, "C" 2, "D" 3, "E" 4)
set ytics ("N0" 0, "N1" 1, "N2" 2, "N3" 3, "N4" 4)
set style line 102 lc rgb'#101010' lt 0 lw 4
set grid front ls 102
set datafile separator ","
plot 'matrix.txt' matrix with image, \
for [i=1:5] '' using 0:(i-1):i with labels font ',12' offset 0,1.2

How to trace fork() inside for loop?

int i;
for(i=1; i<=3; i++)
{
fork();
printf("H\n");
}
Result 14 times H
1)When I try binary tree technique or 2(power)N. I end up with 8 outputs.
2)Also when I take out curly brackets, I end up with 8.
What are the differences?
i=1
fork -----------------------
"H" (printed) "H" (printed)
i=2 (next loop) i=2
fork---------- fork----------
"H" "H" "H" "H"
i=3 i=3 i=3 i=3
fork---- fork---- fork---- fork----
"H" "H" "H" "H" "H" "H" "H" "H"
2+4+8 = 14 prints of "H"
with out the curly brackets you only get the printf after the loop, that's the bottom row,
8 prints of "H"

vbscript compare last value to new

I have a 4 digit field that is constantly renewd and value changes. I need to print the field if the value in the field has changed more then 4 digits.
Example:
field_value=0111
if field_value=0112 (does not print)
if field_value=0116 (prints the value)
As I don't understand your spec - what exactly are your data and how do you measure the difference? - all I can give you is:
Option Explicit
Dim o : o = -1 ' definitely out of range
Dim n
For Each n In Split("0111 0112 0116 9990 9991 9995 9996")
n = CLng(n)
If 4 <= n - o Then
WScript.Echo o, n, "yes"
o = n ' <-- the important part
Else
WScript.Echo o, n, "no"
End If
Next
output:
cscript 25442674.vbs
-1 111 yes
111 112 no
111 116 yes
116 9990 yes
9990 9991 no
9990 9995 yes
9995 9996 no
If you can't specify the first out of range value or need to treat the first differently, you must use a counted loop.

Combine 2 postscript file into pdf

What I am trying to do is combine two postscript files into a pdf. I have already tried using ghostscript to combine them however the issue with that is ghostscript produces a pdf with one ps file on one page and the other on page two which is not what i wish to accomplish
%!PS-Adobe-3.0
%%Pages: 1
%%DocumentData: Clean7Bit
%%LanguageLevel: 2
%%EndComments
%%Page: 1 1
save
6 dict begin currentpagedevice/PageSize get dup 0 get
0 sub 0 sub/w exch
def 1 get 0 sub 0 sub/h exch
def/x 87 def/y 87 def 0 0/b y h mul x
w mul gt def b{w y}{h x}ifelse div/c x h mul y w mul gt def c{w x}{h y}ifelse
div gt{h add translate -90 rotate b{w y h x w mul y div sub 2 div 0}{h
x 0 w y h mul x div sub 2 div}}{translate c{w x 0 h y w mul x div sub 2 div}{h
y w x h mul y div sub 2 div 0}}ifelse ifelse translate div dup scale
end 9 dict begin
{/T currentfile/ASCII85Decode filter def/DeviceGray setcolorspace
/F T/LZWDecode filter def
<</ImageType 1/Width 87/Height 87/BitsPerComponent
1/ImageMatrix[1 0 0 -1 0 87]/Decode
[0 1]/DataSource F>> image
F closefile T closefile}
%%BeginData:;
exec
J3Vsg3$\8+#CjR`&3*WA'+TR\#<!\`;#aOp`$+XV`%h8\!!!K[!9Aet#*;BOP%d==7jS.,hsVBYnDH
N[+5cZ=UtTfLSkWhgRG8\?,WGcN^j5#cP]3KsWRSLmE;_bp<GM2!Q!1FiRE6!+E91]DA$X`8iQFZYB
0mS8-o5Xu!f_0094V'pA:#g3R,3i_$'Yp\)8e-_&1fqhs%"+h!UL4I6R#tNA[6Bt^^UAX[:aRMSIU!
416=^MmJq2-+0!fVFnDer\kkA9UY#Q*n/l#Ih/>7,IEq;.)e7/q%Q&SL"j'""q7'ad9:Z00;\?qF/.
8a*mIt,hY3"qji0!BA*e-tRs6.F-k:_SnL*&QCrBB*lce!!;K8Fj4Hp6d?"Tg3Y4:8BLi#B-/VXSPS
#XP\B&qLYW4;Koo&C`>f_omCk&%aL+C?WTr*(:Q0YB"7Y0#*i?(aUW\?B(Z"l6;3X;8O\%8-n:/*6;
f^!W~>
%%EndData
end restore showpage
%%Trailer
%%EOF
Here is the second file
The file is to big here is a link to it http://pastebin.com/R0Kgarem
Not sure how I would go about solving this problem. I need the 2 ps files under each other without any white space.
Assuming you mean one toward the top of the page and the other toward the bottom of the page (a 2-up), you just need to prevent the first file from executing showpage (by redefining, or editing to remove the word showpage), and then translate (0 -y translate, where y is the height of the first image) before executing the second file. This assumes the first image is already positioned at the top of the page, otherwise you need to translate it to the correct position first.

Resources