Chapter 6. Creating Lists

Whether you’re a car salesman or a carpenter, you use lists every day. Navigating to your Applications folder, scheduling your events for the day, or just shopping for groceries—all require a list of some sort. And just like those lists you make throughout the day, an AppleScript list contains an ordered sequence of items.

AppleScript lists can include just about anything you want—the test scores of several students, for example, or some important to-dos you have to remember. You create lists in AppleScript by surrounding your items in curly brackets—and separating each item with a comma—like this:

{"Feed cat", "Eat breakfast", "Clean out earwax"} --Three strings in a list

Lists don’t have to just store strings, though; you can put numbers, file aliases, and even dates into your lists, like this:

{"Dude", 53.87, alias "", current date}


There’d rarely be a case when you’d want to store a number, file alias, and date within the same list, but you can if you want. A far more common occurrence, though, would be to create a list of just numbers (for tracking test scores) or just aliases (for keeping track of your favorite folders), for example.

A list may contain only a single item, too. You might create a single-item list if you want to note your accomplishments on a particularly uneventful day, for example:

{"Went to sleep"}

Or you can have a list with no items in it—an “empty list.” That’s useful if you need to set aside a list for ...

Get AppleScript: The Missing Manual now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.