Chapter 8. Operators, Expressions, and Statements

IN THIS CHAPTER

  • What are operators?

  • What are expressions?

  • What are statements?

  • Writing scripts

In Chapter 7, you learned quite a bit about variables and properties, and about how you can use the different data types that are available to you. In this chapter, you're going to learn about operators and expressions.

In any language, operators, expressions, and statements play a very important part in getting things done. Like variables, they make programming tasks easier. In this chapter, you're going to learn how to use them to help you put together effective AppleScripts.

Think of these three elements (operators, expressions, and statements) as the proper building blocks of any AppleScript. All AppleScripts are made up of one or more statements. Statements consist of expressions, which in turn may contain operators, variables, objects, and other elements. Because you've already learned about variables, it's time to learn about operators, so that's where you'll start in this chapter.

What Are Operators?

An operator is any symbol, word, or phrase that derives a value from another value or pair of values — and that comes straight from the AppleScript Language Guide. But what does this really mean? Put simply, an AppleScript operator usually has one or two operands (or parts).

Those operators that call for two operands are called binary operators Those operators that operate on a single operand are known as unary operators

For example, one of the ...

Get Apple® Automator with AppleScript® Bible 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.