FANDOM


We will learn the math of Applescript.

Try this code:

set a to 5

set b to 6

set c to a + b

display dialog c

--should display 11

What it does here is sets the vars a & b to 5 & 6, respectively. It then sets the var c to a + b, or 5 + 6, which is 11. c is 11. It then displays c and comes up with 11.

You can do this with anything else. NOTE: The sign for multiplying is * (shift + 8), not x. Same goes for division. The sign for it is / (left to right shift).

The good thing is Applescript uses BODMAS (PEMDAS for others), and doesn't just go from left to right. I'll show you what I mean:

set a to 5 + 6 * 2

display dialog a

--should show 17. If it went left to right, it would show 22.

Brackets,

Operations/Orders/Whatever,

Division,

Multiplication,

Addition,

Subtraction.

If that's not it:

Parentheses,

Exponents,

Multiplication,

Division,

Addition,

Subtraction.

When a is set to 17, It goes BODMAS (or PEDMAS!!!). No brackets, or whatever is next, no division, MULTIPLICATION! Boom! 6 * 2 is 12. Now it's left with 5 + 12. That's 17.

Here's left to right:

5 + 6 * 2

5 + 6 = 11

11 * 2 = 22

See?! They're different!

NOTE: Applescript is limited to math. Be careful!

END OF LESSON 2-1. In PART 2-2, we will have dialog boxes in dialogs. For now, bye!

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.