Yesterday I was trying to figure out how to script a loop in AppleScript. I was trying to use an if statement that would keep going until something stopped it. After a few attempts and the script failing I scoured the web searching for ways to make it work. I ended up on Apple’s AppleScript Language Guide where I found the Repeat statement on page 203 [download the PDF version]. I had a duh! moment from my VisualBasic days. “I need a ‘while’ or ‘for’ loop.”
The Repeat statement allows you to repeat a portion of script until you tell it to stop. It can repeat forever if you want or you can have it end if a certain button is clicked. Here is the code. I’m sure this can be cleaned up so it is not as redundant but that is something I will have to learn. Also, I hope to modify this script to allow user input
As stated in the commented out section, the script continues until the “Stop” button is clicked.


0 Responses to “Throw you for a “Loop””