I’m pretty new to this whole applescript business so this might be simply done.
I feel the applescript studio application I’m working on is getting to big in the sense that all the code is in the same applescript file.
I’m familiar with the c/c++ include system and was wondering if there is any way to split one script into may files without any problems with shared variabled etc.
The mechanism is driven by a command called “load script” (see Standard Additions osax dictionary). Not sure at this point if it works the same for Studio apps, but it should (about variable inheritance). Test this:
→ code in main script
property x : 5 --> property
global y --> global
set y to 7 --> initialize global
set z to 9 --> local variable
set lib to (load script alias "julifos:Users:julifos:Desktop:tst:lib.scpt")
lib's h()
→ code in loaded script (aka “library”)
global x, y, z --> auto-inherit these from caller
to h()
return {x, y, z}
end h
If this doesn’t work (I didn’t test), you can still add a dummy handler to pass the variables. Ie:
→ main script
property x : 5 --> property
global y
set y to 7 --> initialize global
set z to 9 --> local
set lib to (load script alias "julifos:Users:julifos:Desktop:tst:lib.scpt")
lib's setup(x, y, z) --> copy related variables
lib's h() --> do whatever with these
→ library
global a, b, c
to setup(h, j, k)
set a to h
set b to j
set c to k
end setup
to h()
return {a, b, c}
end h
But anyway you could ignore “h()” and use “setup()” to both hold and use the variables