Skencil User's Guide: The Script Registry

The Example Scripts | User Scripting | Skencil's API

## The Script Registry

The script registry contains all user scripts and its contents are used to create the Script menu. The script registry is implemented in the (sub-)package `Sketch.Scripting`. Because the `Scripting` package is not automatically imported by the `Sketch` package, you have to `import Sketch.Scripting` explicitly before accessing the registry functions.

Functions in the registry package:

`AddFunction(name, title, function[, kwargs])`

  Add the function function to the registry under the name name. name is used internally to identify the script and should be unique.

  The parameter title defines the text for the menu-entry.

  The function accepts these optional keyword arguments:

  `script_type = type`

    The type of the script. It can be either `SafeScript` or `AdvancedScript`. Both values are defined in the `Scripting` package. The default is `SafeScript`.

  `menu = menu_spec`

    Defines the sub-menu the script should appear in. The menu_spec can be either a string or a tuple of strings. Each string is the title of a sub-menu.

  `args = argtuple`

    Defines additional positional parameters passed to the script function after the context parameter. argtuple must be a tuple containing these arguments. It defaults to the empty tuple.

Example: Registering the `abut_horizontal` script in the sub-menu `"Arrange"`

    Sketch.Scripting.AddFunction('abut_horizontal', 'Abut Horizontal',
                                 abut_horizontal, menu = 'Arrange')

The Example Scripts | User Scripting | Skencil's API