Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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!

share|improve this question
    
I think my problem might be with return, is there a better way to delay within a handler? –  bookcasey Apr 20 '12 at 23:17
4  
Related tip: you can use keystroke "1" instead of key code. Keystroke lets you type in any text and have it typed for you. –  Nathan Greenstein Apr 20 '12 at 23:52
add comment

1 Answer 1

up vote 9 down vote accepted

Try using delay 2 instead of return 2return exits from the loop!

share|improve this answer
1  
That does the trick. Thank you! –  bookcasey Apr 20 '12 at 23:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.