OpenTimelineIO Hook Scripts are plugins that run at predefined points during the execution of various OTIO functions, for example after an adapter has read a file into memory but before the media linker has run.

To write a new hook script, you create a python source file that defines a

The first argument is the timeline to process, and the second one is a dictionary of arguments that can be passed to it. Only one hook function can be defined per python file.

For example:

```python

defhook_function(tl, arg_dict):

for cl in tl.each_clip():

cl.metadata['example_hook_function_was_here'] =True

return tl

```

This will insert some extra metadata into each clip.

This plugin can then be registered with the system by configuring a plugin manifest.

##Registering Your Hook Script

To create a new OTIO hook script, you need to create a file myhooks.py. Then add a manifest that points at that python file:

```

{

"OTIO_SCHEMA" : "PluginManifest.1",

"hook_scripts" : [

{

"OTIO_SCHEMA" : "HookScript.1",

"name" : "example hook",

"execution_scope" : "in process",

"filepath" : "example.py"

}

],

"hooks" : {

"pre_adapter_write" : ["example hook"],

"post_adapter_read" : []

}

}

```

The ``hook_scripts`` section will register the plugin with the system, and the ``hooks`` section will attach the scripts to hooks.

Then you need to add this manifest to your `$OTIO_PLUGIN_MANIFEST_PATH` environment variable (which is "`:`" separated). You may also define media linkers and adapters via the same manifest.

##Running a Hook Script

If you would like to call a hook script from a plugin, the hooks need not be one of the ones that otio pre-defines. You can have a plugin adapter or media linker, for example, that defines its own hooks and calls your own custom studio specific hook scripts. To run a hook script from your custom code, you can call: