AppleScript math: Addition, subtraction, multiplication, division

AppleScript math FAQ: Can you show some examples of basic AppleScript math operations, like addition, subtraction, multiplication, and division?

Sure, let's take a look at some AppleScript math examples.

AppleScript addition syntax/examples

To add a few numbers together just use the normal set syntax and the + operator, like this AppleScript addition example:

set one to 1
set two to 2
set answer to one + two
display dialog answer

That example displays the number 3.

AppleScript subtraction syntax/examples

Here's a similar example, but this time using AppleScript subtraction:

set one to 1
set two to 2
set answer to two - one
display dialog answer

That will display the number 1.

AppleScript multiplication syntax/examples

AppleScript multiplication looks like this:

set one to 1
set two to 2
set answer to two * two * two * two
display dialog answer

AppleScript division syntax/examples

Finally, AppleScript division looks like this:

set one to 1
set two to 2
set answer to one / two
display dialog answer

Add new comment

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.