Resolved How to redisplay an earlier dialog?

Discussion in 'Mac Programming' started by Riku7, Jul 16, 2015.

  1. Riku7 macrumors regular

    Feb 18, 2014
    I'm new to applescript, couldn't find the answer from a search engine, so...

    My script starts out with a dialog box that asks you to enter a numeric value and click OK.
    Then, it displays a table of information that it has calculated based on the numeric value, and this dialog box comes with buttons "Quit" and "Try another". I can't figure out how to handle "Try another"; What I'd want it to do is to start over and let the user type in a new number. Any ideas?
  2. chown33 Moderator

    Staff Member

    Aug 9, 2009
    What you want is called a loop.

    AppleScript has several looping commands. You can google Applescript loop and find lots of examples, articles, etc. Or if you're learning from a book, look in the index for the word "loop".
  3. superscape macrumors 6502a


    Feb 12, 2008
    East Riding of Yorkshire, UK

    Yep, what you're looking for is a repeat loop. Any decent tutorial should cover them. At the risk of sounding grumpy, I suggest you find one and work through it - it really will repay your time and effort.

    However, just to keep your interest and to help you along, I'd do it something like this:

    set theResult to ""
    repeat while theResult is not "Quit"
        --do some stuff
        set theResult to button returned of (display dialog "Some message" buttons {"Quit", "Try again"})
    end repeat
    Take a look at:
  4. Riku7 thread starter macrumors regular

    Feb 18, 2014
    Ah thank you guys, I got the code working as wished!
    I usually find answers independently but sometimes searching leads nowhere because a beginner doesn't know which terms to look for, or worse, if you aren't experienced enough to know the limitations and capabilities of the language. I'll be sure to read the topic thoroughly so I actually understand the concept for future projects as well! :apple:
  5. chown33 Moderator

    Staff Member

    Aug 9, 2009
    A major benefit of a comprehensive reference is that it's reusable. That is, you can look up things that aren't what you originally looked for. In particular, you can easily see what the name of a command is, so you can read about it or search for it elsewhere.

    For example, a comprehensive AppleScript language reference doc would cover loops, conditionals, error catching, subroutines, etc. In short, you don't have to look for answers independently, because all the subject material is already there in one place.

    As an example of a comprehensive reference, google the search terms applescript language. Here's a few sample results:

    The Wikipedia article alone has links to at least a dozen books and online references.
  6. Riku7 thread starter macrumors regular

    Feb 18, 2014
    Yup, those are exactly some of the sources that I've come by while searching. But surprisingly often, even though I read through multiple examples on the same topic from several different sources, it doesn't always provide an answer to a problem that I'm trying to solve.
    Developing the code in question further, I've been stuck with a new mystery for the past four hours or so. o_O

Share This Page

5 July 16, 2015