Sharing Variables between scripts

Hi everyone,

I have a roofing company that offers multiple products. We use a numbers spread sheet to quote everything, and then when a customer chooses a roofing system, we delete a ton of the erroneous information, fill out our work orders, our sub contractor pay outs, supplier PO’s etc. This is all very tedious and mostly predictable. I have written a script that uses lots of if then logic to decide what to keep and what to delete, etc. but after getting it all working, its a hot mess. There are so many erroneous variables in the script for the different manufacturers, shingle types etc. that any time something changes with a product, for example, it is a search to try and find what I need to change in the script. There is also, not going to lie, a touch of OCD on my part wanting to get things “just right.” This brings me to the new idea…

There are some variables that will apply to every project regardless of what shingle the customer chooses (Address, Name, Phone number etc.)–(High level variables), some variables that will only apply to the manufacturer chosen (Underlay names, warranty options etc.)–(Mid level variables) and some variables that will only apply to the product (Colour, etc.)–(low level variables)

I would like to write the main script that will take all the High Level variables and offer choices that will then trigger other scripts that are specific to the mid and low level variables. The issue I am having is when it comes to getting the variables from the low and mid level scripts to feed into the high level one.

simple example

Script 1

tell application “numbers”
tell table 1 of sheet 1 of document 1
set Shingle to ¬
(choose from list {“GAF”, “CRC”}

if manufacturer is equal to “GAF” then
load script Script2 (I would input the proper path obviously)
end if

display dialog StarterStrip

Script 2
—GAF options

set StarterStrip to “Weather Blocker”

(other variables)


when I do get script2 to load into Script1, it wither says that it can not get the variable, or the variable is undefined. If I set “as string” up it will bring back the result of script2.

Any ideas and help would be greatly appreciated, thanks!


I’m not quite sure if I completely understood what you want.

But sharing vars or splitting up scripts is pretty easy when working with script classes.

Main script:

Property testa:"A"
Property testb:"B"

set sublevelScript to load script file "path:to:script.scpt"
sublevelScript's initMe(me)
sublevelScript's someFunction


On Script sublevelScript
Property parent:missing value

on initMe(parentScript)
Set parent to parentScript

Log parent's testa -- "A"

End script

You can access other sublevelScripts attached to the Main Script by adressing it like: parent’s sublevelScriptB’s someOtherFunction () (from Main script without “parent”)
Written from smartphone without testing.