AppleMods

Loader Commands

The AppleModsTools scripting addition, Loader module and ModuleLoader objects define a number of important commands that are documented below.

Additional commands are documented in the AppleModsTools and Loader dictionaries. To open AppleModsTool’s dictionary in AppleScript Editor, choose File → Open Dictionary… and select the AppleModsTools.osax option from the list. To open Loader’s dictionary, double-click the OpenModuleDictionary application.

AppleModsTools Commands

AppleMods Loader

Returns a Loader module object.

  • AppleMods Loader
    • Loader

Loader Module Commands

The Loader module provides commands for creating ModuleLoader objects.

initScript

Load modules into the given client script. This is the recommended approach.

  • initScript(scpt)
    • scpt : script -- The script that sent this command. Loader will call the script's __load__ handler, passing it a newly created ModuleLoader object.
    • ModuleLoader -- The ModuleLoader object that was used to load the script's modules.

initScript uses path to me to locate the script that called it. If running the script in an application that does not correctly support the path to me command (typically returning its own path, not the script's) then use initScriptAtPath and specify the script's path yourself.

ModuleLoader Object Commands

Locates and loads AppleScript modules from disk.

loadModule

Loads the requested module. ModuleLoader will search all scopes in the following order until a suitable match is found: embedded, local, global.

  • loadModule(modName)
    • modName : text -- The module's name, with optional version requirements; e.g. "Math", "List≥0.2.0".
    • script -- The loaded module.

loadEmbeddedModule

Loads the requested module from the embedded scope only (i.e. the embedded Scripts folder inside a bundle-based .scptd or .app file).

  • loadEmbeddedModule(modName)
    • modName : text -- The module's name, with optional version requirements; e.g. "Math", "List≥0.2.0".
    • script -- The loaded module.

loadLocalModule

Loads the requested module from the local scope only (i.e. the folder that contains the script that made this call).

  • loadLocalModule(modName)
    • modName : text -- The module's name, with optional version requirements; e.g. "Math", "List≥0.2.0".
    • script -- The loaded module.

loadGlobalModule

Loads the requested module from the global scope only (by default, ~/Library/Scripts/AppleMods and /Library/Scripts/AppleMods).

  • loadGlobalModule(modName)
    • modName : text -- The module's name, with optional version requirements; e.g. "Math", "List≥0.2.0".
    • script -- The loaded module.

Specifying the module version(s) to use

By default, Loader will load the first module it finds with a matching name. If the folder being searched contains more than one module with the same name, Loader will load the one with the highest version number in its filename. (Note: unversioned modules are always assumed to be older than versioned modules.)

The loadModule command allows you to specify a single module version or range of acceptable module versions as part of the module name. The syntax for specifying a single version is as follows:

"NAME - VERSION"

To specify a minimum and/or maximum version (square brakets indicate an optional entry):

"NAME [ ≥ VERSION ] [ > VERSION ] [ ≤ VERSION ] [ < VERSION ]"

Note that any whitespace between names, symbols, and versions is ignored.

For example, to load version 0.2.0 of the Foo module:

loadModule("Foo-0.2.0")

or to load version 0.4.0 or newer:

loadModule("Foo ≥ 0.4.0")

or to load version 0.4.0 or newer, but older than version 0.9.0:

loadModule("Foo ≥ 0.4.0 < 0.9.0")

As before, Loader will load the first module it finds with a matching name and acceptable version. If a folder contains a module with matching name but unacceptable version, Loader will proceed to the next available folder.

Note: because Loader stops searching through folders as soon as it finds an acceptable module, it may not load the newest module present on the system. For example, if the local domain contains Foo-0.5.0 and the global domain contains Foo-0.8.0 then the older Foo-0.5.0 will be used since the local domain is searched first.