Create an AppleScript list with the every keyword

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.

Add new comment

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.