Scripting Reference
Here you can find an almost exhaustive reference on Chataigne specific functions.
Scripts in Chataigne are based on a simplified version of Javascript. Most functions are available, but some might be missing. If you're missing some functions, please contact me and consider donating so I can spend more time improving Chataigne !
This documentation only shows functions that I have added on top of JUCE's Javascript Engine. To know all the base functions that are available, you can take a look at the JavascriptEngine's source code
Common Functions
There are few common functions that you can use, no matter the type of script.
None of the functions below are needed when making a script, they are just helper functions. If you don't need them, don't add them in your script as Chataigne will optimize your script depending on the available functions in it.
Method | Description | Example |
---|---|---|
init() | If present, this function will be called right after the script is loaded. |
|
update(deltaTime) | If present, this function will be called regularly at rate specified by the "Update rate" script parameter. This parameter is only visible when the function is present in the script. You can also change the rate from the script by calling script.setUpdateRate(rate). see below for more informations. deltaTime is in seconds, and the rate parameter is in Hz. |
|
messageBoxCallback(id, result) | This function is called when a user has made a choice in a message box launched by this script. |
|
Parameters and triggers
All parameters and triggers have common methods and specific methods
Common methods and properties
Method | Description | Example |
---|---|---|
getParent() | Returns the value of this parameter |
|
setName(name) | Sets the parameters name |
|
setAttribute(attribute, value) | Sets a parameter's attribute. All parameters get : readonly : sets the parameter as not editable description : change the tooltip description enabled : enable or disable this parameter alwaysNotify : set the alwaysNotify flag (if true, this will trigger updates even if setting the same value than before). More information for specific parameters in each parameter's section. |
|
isParameter() | returns whether the target is a parameter or a trigger |
|
name | This is the name identifier of the object, as you would target it in a script. |
|
niceName | This is the "nice name" of the object, as you see it in the Inspector. |
|
getControlAddress ([reference]) | Returns the OSC-style control address of this element. Optional reference parameter allows you to specify a root container to generate the address from. |
|
getScriptControlAddress() | Returns the script control address of this element. |
|
resetValue() | Resets the value to its default |
|
Trigger
Method | Description | Example |
---|---|---|
trigger() | Returns the value of this parameter |
|
Float Parameter
Method | Description | Example |
---|---|---|
get() | Returns the value of this parameter |
|
set(value) | Sets the value of this parameter |
|
setAttribute(attribute, value) | Specific attributes : ui : The UI to use to show this parameter. Accepted values are : time, slider, stepper, label |
|
Integer Parameter
Method | Description | Example |
---|---|---|
get() | Returns the value of this parameter |
|
set(value) | Sets the value of this parameter |
|
setAttribute(attribute, value) | Specific attributes : hexMode : Whether to show the value as decimal or hexadecimal. |
|
Boolean Parameter
Method | Description | Example |
---|---|---|
get() | Returns the value of this parameter |
|
set(value) | Sets the value of this parameter |
|
String Parameter
Method | Description | Example |
---|---|---|
get() | Returns the value of this parameter |
|
set(value) | Sets the value of this parameter |
|
setAttribute(attribute, value) | Specific attributes : multiline: whether the parameter can be multiline prefix: add a prefix before the value suffix: add a suffix after the value |
|
Color Parameter
Method | Description | Example |
---|---|---|
get() | Returns the value of this parameter. The result is an array containing [r,g,b,a], values are between 0 and 1 |
|
set(value) | Sets the value of this parameter. You can either set the value with ARGB hex value, [r,g,b,a] float array, or r,g,b,a separate values. r, g and b values are always between 0 and 1 and alpha is optional (you can specify r,g,b only); |
|
Target Parameter
Method | Description | Example |
---|---|---|
get() | Returns the string value of the target address |
|
getTarget() | Returns the actual selected target |
|
set(value) | Sets the string value of the target's address. |
|
setAttribute(attribute, value) | Specific attributes : targetType : the type of target to search. This can either be "container" or "controllable" root : the root container from which to search searchLevel : specify the max level to search from the root showParameters : if target is controllable, hide or show parameters showTriggers : if target is controllable, hide or show triggers labelLevel : the level of parents to show in the UI. allowedTypes : specify which types of targets are allowed excludedTypes : specify which types of targets are not allowed |
|
Enum Parameter
Method | Description | Example |
---|---|---|
addOption(label, value) | Add an option to the list |
|
get() | 1.6.x : Return the selected key 1.7.x : Return the selected data |
|
getData() | Get the selected data (1.6.x only) |
|
getKey() | Get the selected key (1.7.x only) |
|
removeOptions() | Removes all options. |
|
set(key) | This sets the parameter to the corresponding key. |
|
setData(data) | This sets the parameter to the corresponding data |
|
setNext([loop]) | Sets the value to the next element in list. Loop (optional) : loops throught the list |
|
setPrevious([loop]) | Sets the value to the previous element in list. Loop (optional) : loops throught the list |
|
getAllOptions() | Returns an array with all available option. Each element of the array is an object containing a "key" and a "value" property. |
|
getOptionAt(index) | Return an option at the defined index . This object contains a "key" and a "value" property. |
|
getIndex() | Returns the index of the selected option. |
|
File Parameter
Method | Description | Example |
---|---|---|
setAttribute(attribute, value) | Specific attributes : directoryMode: specify if this parameter should be looking for a file or a folder |
|
readFile([asJSON]) | Get the content of the file. If asJSON is true, then the content will be parsed and returned as an Object. |
|
writeFile(data, overwriteIfExists) | Write the content or a string of an Object to the selected file. If the file exists, overwriteIfExists will let you decide whether to overwrite it or not (false by default). |
|
getAbsolutePath() | Returns the absolute path for this file. |
|
launchFile(arguments**)** | This will launch the selected file with the _arguments _ provided |
|
Point2D Parameter
Method | Description | Example |
---|---|---|
get() | Returns the value of this parameter |
|
set(x, y) | Sets the value of this parameter |
|
Point3D Parameter
Method | Description | Example |
---|---|---|
get() | Returns the value of this parameter |
|
set(x, y, z) | Sets the value of this parameter |
|
Container
Containers are any object that contains parameters or other containers. If you're targetting something from the hierarchy (root.* **** or local.*), this will be either a container of a parameter, so if it's not a parameter, then it's a container.
Method | Description | Example |
---|---|---|
getChild(childName) | Returns the parameter or container with the provided name. |
|
getParent() | Returns the parent container |
|
setName(name, [shortName]) | Changes the name of the container. If shortName is specified, it will set a custom short name that you can access easily from the script. |
|
setCollapsed(value) | Change the collapsed state of the container, if it can be collapsed. |
|
name | This is the name identifier of the object, as you would target it in a script. |
|
niceName | This is the "nice name" of the object, as you see it in the Inspector. |
|
addTrigger(name, description) | This will add a trigger (button). |
|
addFloatParameter(name, description, default, min max) | This will add a float number parameter (slider). |
|
addIntParameter(name, description, default, min max) | add an integer number parameter (stepper), default value of 2, with a range between 0 and 10 |
|
addBoolParameter(name, description, default) | add a boolean parameter (toggle) |
|
addStringParameter(name, description, default) | add a string parameter (text field) |
|
addColorParameter(name, description, default) | add a color parameter (color picker). You can either set the default color with ARGB hex value, [r,g,b,a] float array, or r,g,b,a separate values. r, g and b values are always between 0 and 1 and alpha is optional (you can specify r,g,b only); |
|
addPoint2DParameter(name, description) | add a point 2d parameter |
|
addPoint3DParameter(name, description) | add a point 3d parameter |
|
addTargetParameter(name, description) | add a target parameter (to reference another parameter) |
|
addFileParameter(name, description, [directoryMode]) | Add a file parameter (to reference file or folder on the disk). If directoryMode is set to true a folder instead of a file can be selected. |
|
addEnumParameter(name, description, label1, value1, label2, value2, ...) | Add a enum parameter (dropdown with options) Each pair of values after the first 2 arguments define an option and its linked data |
|
addContainer(name) | Add a container inside of the container. |
|
addAutomation(name) | Adds a curve container |
|
removeContainer(name) | Remove a child container from the container. |
|
removeParameter(name) | Remove a parameter from the container. |
|
getControlAddress ([reference]) | Returns the OSC-style control address of this element. Optional reference parameter allows you to specify a root container to generate the address from. |
|
getScriptControlAddress() | Returns the script control address of this element. |
|
Manager
Managers are special types of container. In the software, you can see that a container is a manager when there is a "+" icon on the right of its block. Well, almost all the times, some of them are just enhanced containers. Most of the times, the managers you will be interested in are the Module manager, the Sequence manager, Layer managers and Automation keys managers.
When a manipulating a manager, you have access to specific functions and properties like adding items, removing items or getting an array of it's items.
Method | Description | Example |
---|---|---|
addItem([type]) | Adds an item to the manager and returns it. Some managers like the Module manager or the layer manager can create multiple types of items. Thus they need a type of item to create, which you must set in the type argument. Other managers like the Sequence manager don't need this argument because there is only one type of sequence. In these cases you don't need to provide an argument when calling the function. |
|
removeItem(item) | Removes an item. item must be a item managed by this manager. |
|
getItems() | Returns an array containing all the items of this manager. |
|
getItemWithName(name) | Returns the first item found with name. This will search for exact match of niceName, shortName, and lowercase version. |
|
getItemAt(index) | Returns the item at the index. |
|
getItemIndex(item) | Returns the index of the specified item. |
|
getItemBefore(item) | Returns the item before the specified item. |
|
getItemAfter(item) | Returns the item after the specified item. |
|
reorderItems() | Reorders all items in this manager. |
|
States
States have dedicated methods to ease the creations of certain items like transitions.
Method | Description | Example |
---|---|---|
addTransition(source, dest) | Adds a transition between two states. source and dest are the two names of the States to transition from/to |
|
Automation
Automations are special managers that handle curves. You can find them in Mapping Layers, or Curve Map filters for instance. They have special methods that you can use to get more specialized info about the curve data.
Method | Description | Example |
---|---|---|
addKey(position, value) | Adds a key at the given position and value |
|
setLength(length, stretch, stickToEnd) | Set a new length for this automation. Stretch allows to stretch all keys to keep relative positioning across the whole automation, stickToEnd forces them to repositioning relative to then end | automation.setLength(12.1, false, false); |
getValueAtPosition(position) | Returns the value of the curve at the given position |
|
getKeyAtPosition(position) | Returns the closest key at the given position | var key = |
getKeysBetween(start, end) | Returns an array of all the keys contained between start and end |
|
Script object
The script object refers to the script container. You can add your own custom parameters here, as well as logging informations, warnings and errors.
Method | Description | Example |
---|---|---|
addTrigger(name, description) | This will add a trigger (button) |
|
addFloatParameter(name, description, default, min max) | This will add a float number parameter (slider). |
|
addIntParameter(name, description, default, min max) | add an integer number parameter (stepper), default value of 2, with a range between 0 and 10 |
|
addBoolParameter(name, description, default) | add a boolean parameter (toggle) |
|
addStringParameter(name, description, default) | add a string parameter (text field) |
|
addColorParameter(name, description, default) | add a color parameter (color picker). You can either set the default color with ARGB hex value, [r,g,b,a] float array, or r,g,b,a separate values. r, g and b values are always between 0 and 1 and alpha is optional (you can specify r,g,b only); |
|
addPoint2DParameter(name, description) | add a point 2d parameter |
|
addPoint3DParameter(name, description) | add a point 3d parameter |
|
addTargetParameter(name, description) | add a target parameter (to reference another parameter) |
|
addFileParameter(name, description, [directoryMode]) | Add a file parameter (to reference file or folder on the disk). If directoryMode is set to true a folder instead of a file can be selected. |
|
addEnumParameter(name, description, label1, value1, label2, value2, ...) | add a enum parameter (dropdown with options) Each pair of values after the first 2 arguments define an option and its linked data |
|
log(message) | Logs a message (must activate "Log" in the script parameters) |
|
logWarning(message) | Logs a message as a warning |
|
logError(message) | Logs a message as an error |
|
setUpdateRate(rate) | Sets the rate at which the update() function is called |
|
setExecutionTimeout( timeInSeconds) | Sets the maximum time that a call in the script can take in seconds. |
|
function scriptParameterChanged (param) | This function will be called each time a parameter of this script has changed. |
|
Root object
The root object refers to Chataigne's engine, which is the root object of all parent. It allows you to access any object in Chataigne's hierarchy. The best way to access them is to right click on a parameter's UI and select "Copy Script control address". Then you can past the address in your script and you will be able to control this parameter.
Local object
The local object depends on where the scripts is running.
If the script is running inside a module, the local variable will referring to the module. You can find all the module functions in the Module Scripts section.
If the script is running inside a condition, the local variable will be referring to the condition. You can find all the condition functions in the Condition Scripts section.
If the script is running inside a filter, the local variable will be referring to the filter. You can find all the filter functions in the Filter Scripts section.
Util object
The util object provides helpers and utility functions like time or conversion.
Method | Description | Example |
---|---|---|
getAppVersion() | Retourne la version actuelle de l'application |
|
getOSInfos() | Returns informations about the OS. The returned object contains the following properties : "name" : name of the OS "type": OS type "computerName": name of the computer language": OS language "username" : name of the logged on user |
|
getEnvironmentVariable(key) | Returns the value of an environment variable from the OS. | v |
getTime() | Returns the time since system start in seconds |
|
getTimestamp() | Returns the time since January 1st 1970 in seconds |
|
delayThreadMS(milliseconds) | delays the scripts execution the amount of milliseconds provided. | util.delayThreadMS(200); |
getFloatFromBytes(byte1, byte2, byte3, byte4) | Returns a float from 4 bytes (big endian, byte1 is most significant) |
|
floatToHexSeq( float, true ) | Returns a Sequence of HEX values from float (4 bytes) (big endian or little endian) |
|
getInt32FromBytes(byte1, byte2, byte3, byte4) | Returns a 32-bit integer from 4 bytes (big endian, byte1 is most significant) |
|
getInt64FromBytes(byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8) | Returns a 64-bit integer from 8 bytes (big endian, byte1 is most significant) |
|
doubleToHexSeq( double, true ) | Returns a Sequence of HEX values from double (8 bytes) (big endian or little endian) |
|
getIPs() | Returns an array of all IP addresses found |
|
hexStringToInt( String ) | Returns Int value from HEX 'string' (from "00" to "FF") |
|
encodeHMAC_SHA1(text, key) | Returns a HMAC-SHA1 encoded string |
|
toBase64(value); | Returns a converted base-64 string from an utf8 string. |
|
fromBase64(value); | Returns a converted data block from a base-64 encoded string |
|
fileExists(path) | Returns true if a file exists at the path provided, otherwise returns false |
|
directoryExists(path) | Returns true if a directory exists at the path provided, otherwise returns false |
|
readFile(path, **** [asJSON]) | Get the content of the file at path. If asJSON is true, then the content will be parsed and returned as an Object. |
|
writeFile(path, data, overwriteIfExists) | Write the content of a string or an Object to the file at path . If the file exists, overwriteIfExists will let you decide whether to overwrite it or not (false by default). |
|
createDirectory(folderPath) | Creates a directory at the path specified. |
|
getObjectProperties(object, includeParameters, includeObjects) | Returns an array of all the properties names of this object. You can specify if you want to include parameters and/or objects (like containers) Default is include all. |
|
getObjectMethods(object) | Returns an array of all the method names of this object. |
|
copyToClipboard(data, data2...) | Copies all data joined into string to the clipboard |
|
getFromClipboard() | Returns the content of the clipboard |
|
showMessageBox(title, message, [icon, buttonText]) | Shows a popup message box with only one button. Additionally to title and message, you can provide an icon (accepted values are "info", "warning", "question" ) and the text of the button. |
|
showOkCancelBox(id, title, message, [icon, button1Text, button2Text]) | Shows a popup message box with only one button. id is the id that will be provided when the messageBoxCallback is called (see Common functions). Additionally to title and message, you can provide an icon (accepted values are "info", "warning", "question" ) and the text of the button. This method will return true if the first button has been clicked, false otherwise |
|
showYesNoCancelBox( id, title, message, [icon, button1Text, button2Text, button3Text] ), | Shows a popup message box with only one button. id is the id that will be provided when the messageBoxCallback is called (see Common functions). Additionally to title and message, you can provide an icon (accepted values are "info", "warning", "question" ) and the text of the button. This method will return either 0,1 or 2 depending on the button that has been clicked. |
|
Last updated