AppleScript Programming/Advanced Code List/Repeat
Tools
General
Sister projects
In other projects
With commandrepeat you can create repetative behavior, that often will shorten the code a lot, if done correctly.
Its basic format is this:
repeat 10 timessay "Hello."end repeat
And it can be used to do a specific task for every item you drop into a script that has been turned into a program.
on open (ListItem)repeat with thisItem in ListItem-- bunch of kick*** codeend repeatend open
One example of actual script that utilizes repeat-function can be foundhere.
While, here is one example of code that will wait until a page in Safari is fully loaded:
tell application "Safari" to activate -- Brings Safari frontmost application.repeattell application "Safari"if source of document in window frontmost contains "</html>" thentell application "Script Editor" to activateexit repeat -- This will quit the loop.elsedelay 1 -- Will wait for 1 second.end ifend tellend repeat
And a useful source can be found from here:www.macobserver.com
The entire series of AppleScript columns at Mac Observer are herewww.macobserver.com/tips/applescript/