By Alvin Alexander. Last updated: August 10, 2018
AppleScript “list” FAQ: How do I do something for every item in an AppleScript list? (or, How do I loop over an AppleScript list?)
Loop over an AppleScript list with the every keyword
I've shown examples of the AppleScript every keyword in other posts, so rather than create anything new, here's a repeat of one of those examples:
set listOfNames to {} tell application "Finder" set filelist to every file of the desktop repeat with currentFile in filelist set currentFileName to (the name of currentFile) copy currentFileName to the end of listOfNames end repeat end tell choose from list listOfNames
As you can see from the code, I create an AppleScript list named filelist by getting the name of every file on my Mac desktop, then loop over that list with the AppleScript repeat keyword.