Registration

Registration covers presenting your Automation 4 Lua script to Aegisub, providing information about it and registering what features it provides.

Features explained

One of the primary concepts in Automation 4 is the feature. A feature is something a script makes available for Aegisub to call back in response to a user action.

A feature is not a plain callback. Rather, it's usually a set of several callback functions as well as some information on how they should be presented to the user in the GUI.

One feature is the macro. A macro is presented as an item in the Automation menu. A macro has a name (the title show in the menu), a description (the text shown on the status bar when hovering over the menu item), a processing function (the function called when the user selects the menu item) and an optional validation function (determines whether the macro can even do any work in the current state.)

Another feature is the export filter. The export filter is presented in the Export dialogue and can be applied during an export operation. Export filters also have a name, description, processing function and then an optional configuration panel provider. The configuration panel provider is a function that returns a configuration dialogue definition structure which will be displayed in the Export dialogue when the export filter is enabled. The settings filled into the configuration panel are passed to the processing function when it is run.

Script information globals

A script can set a few global variables to provide metadata about the script to Aegisub. The information given with these variables are displayed in the Automation Manager dialogue and the Script Info dialogue.

All of these are optional; a script does not have to provide any of these. If no script name is given, the file name is used instead for display purposes.

Registration functions

The registration functions are the functions provided by Automation 4 Lua you can call to make a feature available to Aegisub. You will usually call these in the top level, at the very bottom of your script.

aegisub.register_macro

Synopsis: aegisub.register_macro(name, description, processing_function, validation_function, is_active_function)

Register a macro feature.

aegisub.register_filter

Synopsis: aegisub.register_filter(name, description, priority, processing_function, configuration_panel_provider)

Register an export filter feature.

Feature callback functions

These are the callback functions you provide to the registration functions.

Macro processing function

Signature: process_macro(subtitles, selected_lines, active_line)

Macro processing functions passed to `aegisub.register_macro` must have this signature. The name process_macro is a placeholder for your own function name.

Return value: The macro processing function can return up to two values: a new selected_lines table containing indices of the lines to select after the macro returns, and an index of the line to make the new active_line. If set, the new active line index must be one of the lines in the new selected_lines table.

Macro validation function

Signature: validate_macro(subtitles, selected_lines, active_line)

Macro validation functions passed to `aegisub.register_macro` must have this signature. The name validate_macro is a placeholder for your own function name.

Important, execution time: Validation functions should always run very fast. Do as little work as possible inside this function, because it is run every time the user pulls open the Automation menu, and every millisecond you spend in validate_macro is one millisecond delay in opening the menu. Consider that the user might have very large files open. Don't block the UI.

Return value: Boolean, true if the macro can run given the current state of subtitles, selected_lines and active_line, false if it can not.

In addition to the primary return value, the validation function can return a string. If it does, the description of the macro is set to the string. This is intended for reporting information to the user about why the macro cannot be run, but there may be more uses for it.

Export filter processing function

Signature: process_filter(subtitles, settings)

Export filter processing functions passed to `aegisub.register_filter` must have this signature. The name process_filter is a placeholder for your own function name.

You do not have to worry about undo issues with export filters. You always work on a copy of the subtitle file.

Return value: Nothing.

Export filter configuration panel provider

Signature: get_filter_configuration_panel(subtitles, old_settings)

Export filter configuration panel providers passed to `aegisub.register_filter` must have this signature. The name get_filter_configuration_panel is a placeholder for your own function name.

Important, execution time: This function is called automatically when the user opens the Export dialogue, and Aegisub blocks until it returns with a configuration panel. Consider that the user might have a very large file open, and that every millisecond spent creating your configuration dialogue is one more millisecond the user has to wait for the Export dialogue to open. Don't block the UI.

Return value: A configuration dialogue table. See the page on configuration dialogues for more information on the format of this table.