Scripting - Repeat Until

Discussion in 'Mac Programming' started by Iriverboys, May 2, 2010.

  1. Iriverboys macrumors newbie

    Joined:
    May 2, 2010
    #1
    I'm trying to make a program that repeats a group of actions over and over again. I want the program to end either if the program has repeated a certain number of times or if a certain key is pressed (specifically the escape key). Is there an easy way to do this? If so, what? If not, what would the complicated way be?

    What I want to be done:

    repeat x times or until esc pressed

    action

    end repeat

    What would the coding for this look like in AppleScript?
     
  2. larkost macrumors 6502a

    Joined:
    Oct 13, 2007
    #2
    You are going to have to do two things for this:

    1) Use an "on keyboard down" handler to fire whenever the escape key is pressed and set a variable to tell the other portion that it should stop.

    2) Use a "on idle" handler to actually do the work. You are going to need to set a variable to count down the repetitions in this, and stop calling this back (ie: don't return anything, or drop out of the script).

    Information on both of these can be found using google searches with "AppleScript" + the name of the handler.
     
  3. Iriverboys thread starter macrumors newbie

    Joined:
    May 2, 2010
    #3
    What would these scripts look like?
    Or, more specifically, what exactly would I have to do to do those things?
     
  4. larkost macrumors 6502a

    Joined:
    Oct 13, 2007
    #4
    1) Do some research on the two handlers I have told you about.

    2) Play around with them and learn how they work.

    3) If you get stuck once you have done a lot of this, then ask specific questions.

    I am not going to spoon feed you.
     
  5. Iriverboys thread starter macrumors newbie

    Joined:
    May 2, 2010
    #5
    Thank you very much larkost.

    I was only asking because I have very, very little programming experience and had no clue where I would even begin to work with what you told me.
     

Share This Page