Need Some Help? Have a Tip to Share?

Email me at MacTipper@gmail.com, or, leave a comment!

Subscribe To Our FREE RSS Feed!

Don't miss out on any posts from the Concise MacTipper Blog.

Friday, November 6, 2009

Global Variables in AppleScript

In AppleScript, global variables allow you to define which terms should be shared throughout the entire script. So if you set a global variable you can then access that variable anywhere in the script. Keep in mind though that, unlike properties, you do not define a global variable when you create it:

Open in AppleScript Editor
global multiply_factor

on run
--Define Multiply_Factor
set multiply_factor to 64

--Use it in the math_problem subroutine
set the_answer to math_problem(16, 32)
return the_answer
end run

--This subroutine uses the multiply_factor variable even though we didn't pass it the multiply_factor variable during the run statement.
on math_problem(x, y)
set new_x to x * multiply_factor
set new_y to y * multiply_factor
set final_result to new_x + new_y
return final_result
end math_problem

0 comments:

Post a Comment