O'Reilly logo

AppleScript: The Missing Manual by Adam Goldstein

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Getting Lists from Other Programs

When it comes to lists, AppleScript really shines when you mix it with other programs. That's because other programs deal with their own unique kinds of information—graphics, formatted text, and sound, for example—which you simply can't create in AppleScript alone.

When commanding programs from AppleScript, you'll find yourself using the every keyword all the time. In this chapter alone, for example, you'll use every to get a list of all the words in a text document (see the next page), a list of all the open documents in a single program (Section 6.7.1.1), and even a list of synonyms for a particular word (see the next page). So don't get listless—you're about to go on a wild list-making ride!

Top: Enter every item you want into the dialog box. If you'd like, you can copy some text from another program, and paste it here using -V. Bottom: When you click OK, the script converts your text into a list. In this layout, it's a lot easier to browse.

Figure 6-7. Top: Enter every item you want into the dialog box. If you'd like, you can copy some text from another program, and paste it here using -V. Bottom: When you click OK, the script converts your text into a list. In this layout, it's a lot easier to browse.

TextEdit

When you're scripting TextEdit, lists can come in quite handy for breaking your text into smaller chunks. For instance, you can easily get a list of all the words in the frontmost TextEdit document with this script:

tell application "TextEdit" set wordList to (every word of the front document) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required