Search code examples
applescript

Is there a way to store a variable in an Applescript Library?


So I have a variable that I use in almost every script, which is hard to remember.

I can save it in a custom library as a function, but I want it as a variable.

So for example:

In Script Library "Math":

property infinity: 10 ^ 308.254715 -- biggest possible Number

on infinity()
    return 10 ^ 308.254715 -- biggest possible Number
end infinity

In a normal script:

tell script "Math"
    return infinity -- Produces error about how infinity isn't defined
    return infinity() -- Works
end tell

Is it possible to save it as a variable or am I forced to save it as a function?


Solution

  • With script Math having:

    property infinity: 10 ^ 308.254715
    

    Then in a script other than script Math, you can do the following:

    property infinity : infinity of script "Math"
    

    Then use infinity however you'd like as if property infinity: 10 ^ 308.254715 was in the script.

    Example: return infinity