What is Loader?
Loader is a powerful, easy-to-use module loading system for AppleScript.
What is a module?
A module (also known as a ‘library’) is a compiled AppleScript containing one or more handlers for use by other scripts.
How do I use a module?
The basic (i.e. non-Loader) technique is as follows:
Load the module file using Standard Additions’
load scriptcommand, for example:
load script POSIX file "/Library/Scripts/SomeModule.scpt"
Put the resulting script object in a property so that the rest of your script can access it, for example:
property SomeModule : (load script POSIX file "/Library/Scripts/SomeModule.scpt")
Call the script object’s handlers, for example:
Why use Loader?
Unfortunately, while the ‘load module’ step of the above approach may be simple, it is also crude and inflexible, and only suitable for the most basic of tasks. The Loader system provides a much more powerful and flexible module loading solution that handles both simple and complex requirements with ease.
What does the Loader system consist of?
The Loader system consists of two parts: the AppleModsTools scripting addition, and the
Loader module itself.
The AppleModsTools scripting addition provides a command,
AppleMods Loader, that returns a copy of the
Loader module. Your script can then store this module in a property named
_Loader, for example:
property _Loader : AppleMods Loader
Loader module is responsible for loading modules into your scripts. You can tell Loader to load modules either when your script is compiled or each time it is run. The next chapter has more information on using the
Do I need AppleModsTools to compile scripts?
Using the AppleModsTools scripting addition is the recommended approach for compiling scripts that use Loader. (It is possible to compile scripts without it, but this won’t be covered here.)
Do I need AppleModsTools to run already-compiled scripts?
The AppleModsTools scripting addition is not needed to run compiled scripts, so scripts and applets that have been compiled on a machine with AppleModsTools installed can be run on machines without it as long as they don’t need to be recompiled there.