13.11. Before and After

Some applications let you specify an item relative to another one by using the keywords before and after, or their corresponding synonyms in front of, behind, and in back of.

For example, you can ask the Finder to give you the file after the first file on your desktop by sending it a command like this:

file after first file on desktop

This approach is more practical when you are talking to text editors from your program. You can give this command to TextEdit to give you the paragraph after the first one in your front document window:

paragraph after first paragraph of front document

Of course, this is equivalent to writing the following:

second paragraph of front document

You should note that you can't use before and after to refer to items or properties in a list or record. That means the following will not work:

item after first item of myList  -- Sorry, doesn't work!

The before and after keywords are used primarily when working with word processing applications like TextEdit. They allow you to insert text before and after other text in a document, typically at an insertion point.

Get Beginning AppleScript® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.