Organizing subroutines...

Hi,

When working on an elaborate script, I like to work with small subroutines rather that one big script. I’m working on a project now that has 28 subroutines, plus the “main” part of the script that calls the subroutines. As I develop, I create each subroutine in it’s own .scpt file to keep things neat, but I end up creating one behemoth script with all the subroutines pasted below the main.

I’d like to know if there is a way to keep each subroutine in its own .scpt file, and then use something similar to INCLUDE (form C++) in the main script to tie everything together when I save out as an application. I’ve been looking into application bundles, but haven’t figured out yet if that’s what I’m after.

Thanks. :cool:

You can use load script file which is a part of the Standard Additions scripting addition. You can save handlers and properties in a compiled script, then load that script and use tell/end tell to call sub-routines from within that script. load script returns a script object which can have handlers (sub-routines) and share properties (data).

The Applescript Language Guide contains the info about script objects and their use. The guide is old (1999) but has basic info that is still useful.

Craig

Carl, you can use properties to do what you want.

property subroutine1 : load script (pathToFirstScript)
property subroutine2 : load script (pathToSecondScript)

-- do some stuff

set someProperty of subroutine1 to "Something"
tell subroutine1 to someHandler()

-- do some more stuff

Be sure to check out this unScripted article: Script Libraries

Thanks guys. :cool: