Repository navigation
Scripting Engine
Skin variables has a powerful skin scripting engine for chaining conditional commands together. Scripting engine files are stored in json format and run via RunScript
RunScript(script.skinvariables,run_executebuiltin=special://skin/shortcuts/builtins/commands.json,use_rules=True)
The above runs the command file shortcuts/builtins/commands.json
Any location and filename can be used.
The use_rules=True param must be specified to indicate that the script will be running commands from a file.
Below is a basic example script e.g. our commands.json file
{
"infolabels": {
"fanart_path": "ListItem.Art(fanart)",
"landscape_path": "ListItem.Art(landscape)"
},
"regex": {},
"values": {},
"sums": {},
"decode": {},
"encode": {},
"escape": {},
"capitalize": {},
"lower": {},
"upper": {},
"operations": [],
"actions": [
"SetProperty(Fanart_Path,{fanart_path},Home)",
"SetProperty(Landscape_Path,{landscape_path},Home)"
]
}
In effect this example is equivalent to:
SetProperty(Fanart_Path,$INFO[ListItem.Art(fanart)],Home)
SetProperty(Landscape_Path,$INFO[ListItem.Art(landscape)],Home)
NOTE: The lines with empty sections such as "regex" and "values" etc. are optional and can be removed if empty. They are displayed above to demonstrate possible options.
Retrieves $INFO[info] values and stores as a key
Any infolabel from https://kodi.wiki/view/InfoLabels can be used
"infolabels": {
"key_01": "info_01",
"key_02": "info_02"
}
At times you may want some values to be conditional similar to a $VAR.
Conditional values are specified in the values section and have a list of rules to be met for the corresponding value to be stored into the key. The conditions are evaluated in order until a match is found (similar to how a $VAR might operate).tion)
Example:
{
"infolabels": {
"landscape_path": "ListItem.Art(landscape)",
"fallback_path": "Skin.String(Landscape.FallBack)"
},
"values": {
"image_path": [
{
"rules": ["{landscape_path}!="],
"value": "{landscape_path}"
},
{
"rules": ["{fallback_path}!="],
"value": "{fallback_path}"
},
"special://skin/extras/backgrounds/default.jpg"
]
},
"actions": [
"SetProperty(Landscape_Path,{image_path},Home)"
]
}
In effect this example is equivalent to:
<variable name="image_path">
<value condition="!String.ISEmpty(ListItem.Art(landscape))">$INFO[ListItem.Art(landscape)]</value>
<value condition="!String.ISEmpty(Skin.String(Landscape.FallBack))">$INFO[Skin.String(Landscape.FallBack)]</value>
<value>special://skin/extras/backgrounds/default.jpg</value>
</variable>
SetProperty(Landscape_Path,$VAR[image_path],Home)
| Operator | Description | Example |
|---|---|---|
== |
Equal |
["{color}==blue"] "value in color equals blue" |
!= |
Not Equal |
["{color}!=blue"] "value in color does not equal blue" |
<< |
Contains |
["{color}<<blue"] "value in color contains blue" e.g. also matches if value is "deep blue" or "light blue" or "blue green" etc. |
>> |
Contained |
["{color}>>blue"] "value in color contained in blue" i.e. reverse of contains |
!< |
Not Contains |
["{color}!<blue"] "value in color does not contain blue" i.e. inverse of contains |
!> |
Not Contained |
["{color}!>blue"] "value in color is not contained in blue" i.e. inverse of contained |
Rules to compare against an empty value is as simple as leaving the other side of the operator blank
Example ["{color}=="] is "the value in color is empty"
Example ["{color}!="] is "the value in color is not empty"
Rules can also use skin engine booleans as conditions.
Any boolean from https://kodi.wiki/view/List_of_boolean_conditions can be used
Example: The value in color contains blue and the videoosd window is visible:
"rules": [
"{color}<<blue",
"Window.IsVisible(videoosd)"
]
Rules can be chained together as a list of AND conditions where all conditions must be met.
AND conditions are a comma separated list of conditions.
Example: Match where value in color contains "blue" but not "deep" so matches "blue" or "light blue" or "blue green" but not "deep blue"
"rules": [
"{color}<<blue",
"{color}!<deep"
]
Rules can also specify an OR condition with a double pipe || symbol
Example: Match where value in color contains either blue or green
["{color}<<blue||{color}<<green"]
Example: Match where value in color contains "blue" or "green" but not "deep"
"rules": [
"{color}<<blue||{color}<<green",
"{color}!<deep"
]
Example: Modify the capitalization of the value stored in key and output to a different key
"capitalize": {"capitalized_key": "{key}"},
"upper": {"upper_key": "{key}"},
"lower": {"lower_key": "{key}"}
Use a regex condition to substitute a value using re.sub()
Example: Substitute all numbers found in key with an "X" and output back to key
"regex": {
"key": {
"regex": "[0-9]",
"value": "X",
"input": "{key}"
}
}
Example: Sum a list of numbers together
"sums": {"total_value": ["{key_01}", "{key_02}", "{key_03}"]}
Apply URL decoding/encoding
Example:
"decode": {"decoded_key": "{key}"},
"encode": {"encoded_key": "{key}"}
Apply XML escaping e.g. convert & to &
Example:
"escape": {"escaped_key": "{key}"}
By default the order of operations that occur before actions are:
- infolabels
- regex
- values
- sums
- decode
- encode
- escape
- lower
- upper
However, at times you may wish to specify a custom order for operations (e.g. to do regex after values etc.).
A custom list of operations can be specified with the operations list. The list of operations is conducted after all main operations complete but before actions.
Example:
"operations": [
{"values": {VALUES_SECTION_GOES_HERE}},
{"regex": {REGEX_SECTION_GOES_HERE}}
[etc]
]
At times you may also wish to specify the value of a key at the moment of running the script itself. These key value pairs can be specified when running the script itself. Any key name can be used as long as it doesn't conflict with some other script command used by skin variables.
Example: Set key_01 to value_01 and key_02 to $INFO[System.Time]
RunScript(
script.skinvariables,
run_executebuiltin=special://skin/shortcuts/builtins/commands.json,
use_rules=True,
key_01=value_01,
key_02=$INFO[System.Time]
)
The above example is split onto separate lines for readability. Use as a single line command.
🔖 v2.3.5+
Several Tools and Helpers accept a run_script= param. Once the helper has created its items and set any window properties, it runs the specified script file. The item values from the helper are passed to the script as keys.
<onclick>RunPlugin("plugin://script.skinvariables/?info=get_encoded_string&window_prop=MyEncodedString&window_id=Home&run_script=myscript.json&&Umläuts,‡†Special Characters")</onclick>
The same param works with the helper used as a container <content> path. Note that the script runs again each time the container refreshes.
Supported helpers
| Helper | Item values |
|---|---|
get_split_string |
{label} |
get_encoded_string |
{label} |
get_number_sum |
{label} |
get_refresh_counter |
{label} |
get_file_exists |
{label} is the path. {property_fileexists} is the path if the file exists, otherwise empty |
get_file_size |
{label} is the path. {property_filesize_b} {property_filesize_kb} {property_filesize_mb} {property_filesize_gb}
|
get_argb_colors |
{label} is the colour hex. {property_alpha_hex} {property_alpha_int} {property_alpha_pct} and the same for red green blue
|
get_jsonrpc |
{label} is the method. Each returned value as {property_KEY}
|
get_selected_item |
{label} plus each of the requested infolabels= and artwork=
|
| Value | Resolves to |
|---|---|
run_script=myscript.json |
special://skin/shortcuts/myscript.json |
run_script=/myscripts/myscript.json |
special://skin/shortcuts/myscripts/myscript.json |
run_script=special://profile/myscript.json |
special://profile/myscript.json |
Other path types such as C:\, smb:// or nfs:// are not accepted.
Item values are named after the ListItem infolabel they correspond to. Key names are lowercase and dots . are replaced with underscores _.
| Infolabel | Key |
|---|---|
ListItem.Label |
{label} |
ListItem.Title |
{title} |
ListItem.Property(name) |
{property_name} |
ListItem.Property(FileSize.MB) |
{property_filesize_mb} |
ListItem.Art(poster) |
{art_poster} |
ListItem.Art(tvshow.poster) |
{art_tvshow_poster} |
The first item's values use the standard key names above. Every item is also passed individually with a listitem_X_ prefix, where X is the item's position starting from 0 (the same numbering as the WINDOW_PROP.X window properties). The {count} key holds the number of items.
plugin://script.skinvariables/?info=get_split_string&values=Action|Comedy&run_script=myscript.json
| Key | Value |
|---|---|
{label} |
Action |
{listitem_0_label} |
Action |
{listitem_1_label} |
Comedy |
{count} |
2 |
The params passed to the helper are also available to the script with a param_ prefix, e.g. {param_window_prop} or {param_info}. Paths passed after double ampersands && are numbered from 0, e.g. {param_paths_0}.
Run get_selected_item and use the item values in special://skin/shortcuts/selected.json
<onclick>RunPlugin(plugin://script.skinvariables/?info=get_selected_item&container=50&infolabels=Title/Property(dbtype)&artwork=poster/tvshow.poster&run_script=selected.json)</onclick>
{
"actions": [
[
{
"rules": ["{property_dbtype}==episode"],
"value": "SetProperty(SelectedPoster,{art_tvshow_poster},Home)"
},
{
"rules": [],
"value": "SetProperty(SelectedPoster,{art_poster},Home)"
}
],
"SetProperty(SelectedTitle,{title},Home)"
]
}The poster rules are in a sublist so that the title is still set after a rule matches. See Conditional Actions.
Actions can also be conditional, with multiple actions chained as values. Conditional actions function the same as $VAR[] in that the actions will exit after the first block where the rules are true
Example:
"actions": [
{
"rules": ["Container.IsUpdating"],
"value": [
"Notification(Container,Is Updating)",
"SetProperty(ContainerUpdating,True)"
]
},
"{beyond_here_does_not_complete_if_container_is_updating}",
"Notification(Container,Is Not Updating)",
"SetProperty(ContainerUpdating,False)"
]Sometimes you might want to have conditional actions but not have the script stop on a true condition. For this purpose, actions can be split out into a sublist of actions using [] square brackets. The sublist will evaluate separately similar to a nested $VAR[] to allow the action list to continue after the sublist block.
"actions": [
[
{
"rules": ["Container.IsUpdating"],
"value": [
"Notification(Container,Is Updating)",
"SetProperty(ContainerUpdating,True)"
]
}
],
"{these_actions_below_will_complete_even_if_container_is_updating_due_to_conditional_rules_in_sublist}",
"Notification(Container,Is Not Updating)",
"SetProperty(ContainerUpdating,False)"
]A sleep command can be used to wait between actions
Example:
"actions": [
"Notification(SV,Sleep for 2.5 seconds)",
"sleep=2.5",
"Notification(SV,Wake Up)"
]
Occasionally you might want to reroute back to a skinvariables script. If you use the normal RunScript approach, the command will be triggered and then the next action will run immediately. However, it might be necessary to wait for the script to complete first. In that case use route=
Example:
"actions": [
"route=run_executebuiltin=special://skin/shortcuts/builtins/other_commands.json&use_rules=True",
"Notification(SV,Other Commands Completed)"
]
More advanced actions that normally wouldn't be permitted by the skinning engine are also possible such as using a variable command from a key
Example: Use command stored in a window property:
"infolabels": {
"string_command": "Window.Property(StringCommand)",
"string_name": "Window.Property(StringName)",
"string_value": "Window.Property(StringValue)"
}
"actions": [
"{string_command}({string_name},{string_value})"
]
If we run SetProperty(StringCommand,Skin.SetString) before running the above then it will run as:
Skin.SetString($INFO[Window.Property(StringName)],$INFO[Window.Property(StringValue)])
If we run SetProperty(StringCommand,SetProperty) however, then the above will run as this instead:
SetProperty($INFO[Window.Property(StringName)],$INFO[Window.Property(StringValue)])