Simple auto-typer with AppleScript I want to make a small application that will type the number 1, wait an interval, type the number 2, wait an interval, type number 3, wait an interval, etc.

This works for typing one number over and over:

on idle
    tell application "System Events"
        key code 18
    end tell
    return 2
end idle


But I'm struggling to get more than number to work:

on idle
    tell application "System Events"
        key code 18
    end tell
    return 2
    tell application "System Events"
        key code 19
    end tell
    return 2
end idle


This doesn't work. Nor does this:

on idle
    tell application "System Events"
        key code 18
        return 2
        key code 19
        return 2
    end tell
end idle


I don't know what else to try. Thank you!
Try using delay 2 instead of return 2 — return exits from the loop!