I've been trying to do my own AppleScript to make my Mac press C 13 times, press the left arrow key, press C 13 times, press the right arrow key and start from the beginning repeatedly at 1.7 seconds intervals.
Currently I have only managed to do a working script that makes it press C multiple times. Could someone please help me with this? This is what I have at the moment
set i to 0
repeat while i < 1.0E+300
set i to i + 1
delay 1.7
tell application "System Events" to keystroke "c"
end repeat
Best Answer
To start off, the number
1.0E+300
is a really REALLY big number. That's more than the number of atoms in the entire universe by several orders.Your script isn't far off. To press
"c"
thirteen times, you can either do this:(you potentially need a small delay there to register individual keystrokes, but you can try it without and see which works);
or you can do this:
which is the equivalent of the repeat loop without the delay.
The left and right arrow keys are
key code 123
andkey code 124
, respectively. So, adding those in between the keystrokes:OR:
Finally, doing this ad infinitum on a loop at 1.7 second intervals, will produce something resembling this:
Note that the outside-most repeat loop has no
while
,until
, ortimes
to limit its continuation. It will loop forever, until you stop the script manually.I also didn't factor the 0.1-second delays into the overall 1.7-second delay. The smaller delays will exceed 1.7 seconds in total, but I'll let you adjust the timings to your needs.