Examples|History

Not Frequently Asked Questions

What is a Library ?

A library is a script file which is loaded into other script files. A library is a unit of shared code.

Dividing your code into multiple parts and sharing these between projects will help to develop a sophisticated script with less cost.

For ModuleLoader, any files saved by Script Editor can be a library i.e. script files(.scpt files), script bundles(.scptd files), script applications and script source files(.applescript files). Any special code are not required for libraries.

What are advantages over "load script" command ?

ModuleLoader can minimizes code to manage and to load libraries with following features.

Woking with a few libraries using "load script" command may not problematic. But it is a painful task loading and managing several libraries which have some dependencies by "load script" command.

It is recommended to utilize ModuleLoader or "AppleScript Libraries" for loading libraries instead of "load script" command.

Where Libraries Placed in ?

The default locations to search for libraries are follwing directories under user's home directory and root directory.

Also see the next section to add directories to locations to search for libraries.

The current settings of directries to search for libraries can be obtained with "module_paths" handler.

Adding Folders to Search for Libraries

At first, consider to utilize a Local Loader. You can make flexibile locations to place libraries by the local loader.

If you want to add custom locations for libraries temporary, use set_additional_paths handler or prepend_path handler of the loader script.

The Case When a Library is Loaded More Than Once

If libraries are loaded through execution of "boot (module loader) for me" statement, same name libraries share same substance. This feature allow to minimize script size and to exchange data between libraries through a library.

An example will be shown. The following code is a loaded library.

property _message : "hello"

on set_message(msg)
set my _message to msg
end set_message

on say_message()
return my message
end say_message

In the following code, the library "ShareMessage" is loaded twice into two different properties. The property of one library of "ShareMessage1" is changed by set_message("hey"). The change affects the other library of "ShareMessage2". This means ShareMessage1 and ShareMessage2 share same substance.

property ShareMessage1 : "@module ShareMessage"
property ShareMessage2 : "@module ShareMessage"
script "ModuleLoader"'s setup(me)

log ShareMessage1's say_message() -- result : "hello"
log ShareMessage1's say_message() -- result : "hello"

ShareMessage1's set_message("hey")
log ShareMessage1's say_message() -- result : "hey"
log ShareMessage1's say_message() -- result : "hey"

-- ShareMessage1 and ShareMessage2 share same substance.

Priority between kind of files.

If following files which have same name exists in Script Libraries, the priority to load is following order.

Examples|History