MacOS – How to send two keystrokes that repeat in AppleScript

applescriptmacos

I have something like

tell application "System Events"

set x to "x"

delay 1

repeat

delay 3

keystroke x

end repeat

set y to "y"

delay 1

repeat

delay 5

keystroke y

end repeat

end tell

but it never keystrokes y, it only keystrokes x, and when I reverse it it waits 5 second to do y first, but I just want x to repeat every 3 seconds and y every 5 seconds.

Best Answer

You didn't specify how many times the loop will run. You can try something like this:

tell application "System Events"
    set x to "x"
    repeat 3 times
        keystroke x
        delay 3
    end repeat
    set y to "y"
    repeat 5 times
        keystroke y
        delay 5
    end repeat
end tell