<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://kodi.wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=KenV99</id>
	<title>Official Kodi Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://kodi.wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=KenV99"/>
	<link rel="alternate" type="text/html" href="https://kodi.wiki/view/Special:Contributions/KenV99"/>
	<updated>2026-06-16T20:03:39Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=123641</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=123641"/>
		<updated>2016-07-28T13:05:03Z</updated>

		<summary type="html">&lt;p&gt;KenV99: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=script.service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.9&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi&lt;br /&gt;
|Description=Provides user definable actions for specific events within Kodi. Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=en&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Website=http://kodi.wiki/view/Add-on:Kodi_Callbacks&lt;br /&gt;
|Source=https://github.com/KenV99/script.service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
|icon url=http://mirrors.kodi.tv/addons/jarvis/script.service.kodi.callbacks/icon.png}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Page content goes here --&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&amp;lt;s&amp;gt;The script is not currently available via the official repo but has been submitted as of 27-02-2016.&amp;lt;/s&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
The addon is now available through the official repo (isengard forward) as of 22-04-2016!!!&amp;lt;br /&amp;gt;&lt;br /&gt;
It has one dependency - the requests module. This should automatically be installed by Kodi.&amp;lt;br /&amp;gt;&lt;br /&gt;
If desired, it can also be downloaded manually copied to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
PLEASE NOTE: If you are updating from an installation from before 2-27-2016 (version 0.9.7.6 or earlier), you will be required to reset the settings to default and re-input them. I apologize, this could not be avoided.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python, script or json-rpc-notify.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* A note on Unicode filenames and directories:&lt;br /&gt;
*# Please note that using scripts or python files with names with unicode characters beyond the ASCII character set for the above two task types is NOT uniformly supported on all platforms.&lt;br /&gt;
*# To ensure that your files work, avoid using filenames or placing the files in directories with names that are outside the ASCII character set.&lt;br /&gt;
&lt;br /&gt;
* For http:&lt;br /&gt;
*# Put only the url with port here. Further specification will be done on the events page when invoking this task.&lt;br /&gt;
*# Optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
*# Choose which http request type is desired (most commonly GET or POST).&lt;br /&gt;
*# For POST or PUT, choose what Content-Type you want in the header.&lt;br /&gt;
*# Other CGI query type data (i.e ?var1=x&amp;amp;var2=y) will be done on the events page.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications. This is a json notification receiver event. It is completely separate from the json-rpc-notify TASK which sends notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
*A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
*The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
*Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
*To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
*Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
*If you need to ensure that a space is not split, for a space use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
*Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
*   -Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
*When the task that is being run is an http task using either POST or PUT, anything following double question-mark &amp;quot;??&amp;quot; will be treated as payload.&lt;br /&gt;
*# The ?? will not appear as part of the transmitted url string.&lt;br /&gt;
*# What you put following the ?? should depend on the Content-Type selected for the task on the Tasks settings page.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. See below for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the userdata/addon_data/script.service.kodi.callbacks/lib/usertasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
If you have the [http://addons.kodi.tv/show/script.xbmc.debug.log/ Kodi log uploader addon] installed, then you will see a clickable link to send your log directly from this page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to provide information via a settings page to configure it properly.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: &#039;&#039;userdata/addon_data/script.service.kodi.callbacks/lib/tasks&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example scripts:&#039;&#039;&#039;&lt;br /&gt;
* To have a script execute after Kodi exits on windows while passing pid as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;@echo off&lt;br /&gt;
:loop&lt;br /&gt;
tasklist | find &amp;quot; %1 &amp;quot; &amp;gt;nul&lt;br /&gt;
if not errorlevel 1 (&lt;br /&gt;
    timeout /t 2 &amp;gt;nul&lt;br /&gt;
    goto :loop&lt;br /&gt;
)&lt;br /&gt;
REM Put the code you want to run here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script execute after Kodi exits in other OS&#039;s while passing pid as an argument:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
while kill -0 $1 &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
do&lt;br /&gt;
    sleep 0.2&lt;br /&gt;
done&lt;br /&gt;
# insert your code here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script run as sudo while passing the full path to script as a parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
bash &amp;quot;$*&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If things broke after a new update, please try rebuilding your settings first:&lt;br /&gt;
# Note down your settings&lt;br /&gt;
# On the settings page click &#039;Default&#039; and then click &#039;OK&#039;&lt;br /&gt;
# Rebuid your settings&lt;br /&gt;
# Click OK&lt;br /&gt;
# Restart Kodi&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected after trying the above,&lt;br /&gt;
# From the &#039;General&#039; Settings page:&lt;br /&gt;
## Turn on &#039;Show debugging info in normal log&#039;&lt;br /&gt;
## Click OK&lt;br /&gt;
## Recreate your problem&lt;br /&gt;
## Go back to Settings and on the General page, click to write your settings into the log.&lt;br /&gt;
## Exit Kodi&lt;br /&gt;
# Find your log file: [[Log_file/Advanced#Location|Wiki: Log File Location]]&lt;br /&gt;
# UPLOAD AN &#039;&#039;&#039;ENTIRE&#039;&#039;&#039; COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin]&lt;br /&gt;
# INCLUDE A LINK TO THE LOG IN YOUR POST ON THE FORUM&lt;br /&gt;
&lt;br /&gt;
Please do not turn on Kodi&#039;s debug mode before uploading a log unless asked to do so. This typically just generates more noise in the log, making it harder to pinpoint the problem.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
If you are going to edit python for Kodi, PyCharm is the way to go!!!&lt;br /&gt;
You can apply for a free license to open source projects.&lt;br /&gt;
&lt;br /&gt;
[[File:Icon_PyCharm.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Isengard add-on repository]]&lt;br /&gt;
[[Category:Jarvis add-on repository]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=123174</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=123174"/>
		<updated>2016-06-10T21:44:39Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Settings - Tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=script.service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.9&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi&lt;br /&gt;
|Description=Provides user definable actions for specific events within Kodi. Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=en&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Website=http://kodi.wiki/view/Add-on:Kodi_Callbacks&lt;br /&gt;
|Source=https://github.com/KenV99/script.service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
|icon url=http://mirrors.kodi.tv/addons/jarvis/script.service.kodi.callbacks/icon.png}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Page content goes here --&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&amp;lt;s&amp;gt;The script is not currently available via the official repo but has been submitted as of 27-02-2016.&amp;lt;/s&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
The addon is now available through the official repo (isengard forward) as of 22-04-2016!!!&amp;lt;br /&amp;gt;&lt;br /&gt;
It has one dependency - the requests module. This should automatically be installed by Kodi.&amp;lt;br /&amp;gt;&lt;br /&gt;
If desired, it can also be downloaded manually copied to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python, script or json-rpc-notify.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* A note on Unicode filenames and directories:&lt;br /&gt;
*# Please note that using scripts or python files with names with unicode characters beyond the ASCII character set for the above two task types is NOT uniformly supported on all platforms.&lt;br /&gt;
*# To ensure that your files work, avoid using filenames or placing the files in directories with names that are outside the ASCII character set.&lt;br /&gt;
&lt;br /&gt;
* For http:&lt;br /&gt;
*# Put only the url with port here. Further specification will be done on the events page when invoking this task.&lt;br /&gt;
*# Optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
*# Choose which http request type is desired (most commonly GET or POST).&lt;br /&gt;
*# For POST or PUT, choose what Content-Type you want in the header.&lt;br /&gt;
*# Other CGI query type data (i.e ?var1=x&amp;amp;var2=y) will be done on the events page.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications. This is a json notification receiver event. It is completely separate from the json-rpc-notify TASK which sends notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
*A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
*The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
*Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
*To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
*Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
*If you need to ensure that a space is not split, for a space use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
*Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
*   -Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
*When the task that is being run is an http task using either POST or PUT, anything following double question-mark &amp;quot;??&amp;quot; will be treated as payload.&lt;br /&gt;
*# The ?? will not appear as part of the transmitted url string.&lt;br /&gt;
*# What you put following the ?? should depend on the Content-Type selected for the task on the Tasks settings page.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. See below for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the userdata/addon_data/script.service.kodi.callbacks/lib/usertasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
If you have the [http://addons.kodi.tv/show/script.xbmc.debug.log/ Kodi log uploader addon] installed, then you will see a clickable link to send your log directly from this page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to provide information via a settings page to configure it properly.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: &#039;&#039;userdata/addon_data/script.service.kodi.callbacks/lib/tasks&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example scripts:&#039;&#039;&#039;&lt;br /&gt;
* To have a script execute after Kodi exits on windows while passing pid as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;@echo off&lt;br /&gt;
:loop&lt;br /&gt;
tasklist | find &amp;quot; %1 &amp;quot; &amp;gt;nul&lt;br /&gt;
if not errorlevel 1 (&lt;br /&gt;
    timeout /t 2 &amp;gt;nul&lt;br /&gt;
    goto :loop&lt;br /&gt;
)&lt;br /&gt;
REM Put the code you want to run here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script execute after Kodi exits in other OS&#039;s while passing pid as an argument:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
while kill -0 $1 &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
do&lt;br /&gt;
    sleep 0.2&lt;br /&gt;
done&lt;br /&gt;
# insert your code here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script run as sudo while passing the full path to script as a parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
bash &amp;quot;$*&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If things broke after a new update, please try rebuilding your settings first:&lt;br /&gt;
# Note down your settings&lt;br /&gt;
# On the settings page click &#039;Default&#039; and then click &#039;OK&#039;&lt;br /&gt;
# Rebuid your settings&lt;br /&gt;
# Click OK&lt;br /&gt;
# Restart Kodi&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected after trying the above,&lt;br /&gt;
# From the &#039;General&#039; Settings page:&lt;br /&gt;
## Turn on &#039;Show debugging info in normal log&#039;&lt;br /&gt;
## Click OK&lt;br /&gt;
## Recreate your problem&lt;br /&gt;
## Go back to Settings and on the General page, click to write your settings into the log.&lt;br /&gt;
## Exit Kodi&lt;br /&gt;
# Find your log file: [[Log_file/Advanced#Location|Wiki: Log File Location]]&lt;br /&gt;
# UPLOAD AN &#039;&#039;&#039;ENTIRE&#039;&#039;&#039; COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin]&lt;br /&gt;
# INCLUDE A LINK TO THE LOG IN YOUR POST ON THE FORUM&lt;br /&gt;
&lt;br /&gt;
Please do not turn on Kodi&#039;s debug mode before uploading a log unless asked to do so. This typically just generates more noise in the log, making it harder to pinpoint the problem.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
If you are going to edit python for Kodi, PyCharm is the way to go!!!&lt;br /&gt;
You can apply for a free license to open source projects.&lt;br /&gt;
&lt;br /&gt;
[[File:Icon_PyCharm.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Isengard add-on repository]]&lt;br /&gt;
[[Category:Jarvis add-on repository]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=122926</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=122926"/>
		<updated>2016-05-25T14:06:01Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* FAQs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=script.service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.9&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
|icon url=https://raw.githubusercontent.com/KenV99/script.service.kodi.callbacks/master/icon.png}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Page content goes here --&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&amp;lt;s&amp;gt;The script is not currently available via the official repo but has been submitted as of 27-02-2016.&amp;lt;/s&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
The addon is now available through the official repo (isengard forward) as of 22-04-2016!!!&amp;lt;br /&amp;gt;&lt;br /&gt;
It has one dependency - the requests module. This should automatically be installed by Kodi.&amp;lt;br /&amp;gt;&lt;br /&gt;
If desired, it can also be downloaded manually copied to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python, script or json-rpc-notify.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http:&lt;br /&gt;
*# Put only the url with port here. Further specification will be done on the events page when invoking this task.&lt;br /&gt;
*# Optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
*# Choose which http request type is desired (most commonly GET or POST).&lt;br /&gt;
*# For POST or PUT, choose what Content-Type you want in the header.&lt;br /&gt;
*# Other CGI query type data (i.e ?var1=x&amp;amp;var2=y) will be done on the events page.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications. This is a json notification receiver event. It is completely separate from the json-rpc-notify TASK which sends notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
*A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
*The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
*Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
*To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
*Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
*If you need to ensure that a space is not split, for a space use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
*Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
*   -Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
*When the task that is being run is an http task using either POST or PUT, anything following double question-mark &amp;quot;??&amp;quot; will be treated as payload.&lt;br /&gt;
*# The ?? will not appear as part of the transmitted url string.&lt;br /&gt;
*# What you put following the ?? should depend on the Content-Type selected for the task on the Tasks settings page.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. See below for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the userdata/addon_data/script.service.kodi.callbacks/lib/usertasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
If you have the [http://addons.kodi.tv/show/script.xbmc.debug.log/ Kodi log uploader addon] installed, then you will see a clickable link to send your log directly from this page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to provide information via a settings page to configure it properly.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: &#039;&#039;userdata/addon_data/script.service.kodi.callbacks/lib/tasks&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example scripts:&#039;&#039;&#039;&lt;br /&gt;
* To have a script execute after Kodi exits on windows while passing pid as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;@echo off&lt;br /&gt;
:loop&lt;br /&gt;
tasklist | find &amp;quot; %1 &amp;quot; &amp;gt;nul&lt;br /&gt;
if not errorlevel 1 (&lt;br /&gt;
    timeout /t 2 &amp;gt;nul&lt;br /&gt;
    goto :loop&lt;br /&gt;
)&lt;br /&gt;
REM Put the code you want to run here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script execute after Kodi exits in other OS&#039;s while passing pid as an argument:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
while kill -0 $1 &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
do&lt;br /&gt;
    sleep 0.2&lt;br /&gt;
done&lt;br /&gt;
# insert your code here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script run as sudo while passing the full path to script as a parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
bash &amp;quot;$*&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If things broke after a new update, please try rebuilding your settings first:&lt;br /&gt;
# Note down your settings&lt;br /&gt;
# On the settings page click &#039;Default&#039; and then click &#039;OK&#039;&lt;br /&gt;
# Rebuid your settings&lt;br /&gt;
# Click OK&lt;br /&gt;
# Restart Kodi&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected after trying the above,&lt;br /&gt;
# From the &#039;General&#039; Settings page:&lt;br /&gt;
## Turn on &#039;Show debugging info in normal log&#039;&lt;br /&gt;
## Click OK&lt;br /&gt;
## Recreate your problem&lt;br /&gt;
## Go back to Settings and on the General page, click to write your settings into the log.&lt;br /&gt;
## Exit Kodi&lt;br /&gt;
# Find your log file: [[Log_file/Advanced#Location|Wiki: Log File Location]]&lt;br /&gt;
# UPLOAD AN &#039;&#039;&#039;ENTIRE&#039;&#039;&#039; COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin]&lt;br /&gt;
# INCLUDE A LINK TO THE LOG IN YOUR POST ON THE FORUM&lt;br /&gt;
&lt;br /&gt;
Please do not turn on Kodi&#039;s debug mode before uploading a log unless asked to do so. This typically just generates more noise in the log, making it harder to pinpoint the problem.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
If you are going to edit python for Kodi, PyCharm is the way to go!!!&lt;br /&gt;
You can apply for a free license to open source projects.&lt;br /&gt;
&lt;br /&gt;
[[File:Icon_PyCharm.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Isengard add-on repository]]&lt;br /&gt;
[[Category:Jarvis add-on repository]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=File:Icon_PyCharm.png&amp;diff=122925</id>
		<title>File:Icon PyCharm.png</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=File:Icon_PyCharm.png&amp;diff=122925"/>
		<updated>2016-05-25T14:03:45Z</updated>

		<summary type="html">&lt;p&gt;KenV99: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=122635</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=122635"/>
		<updated>2016-04-23T12:31:48Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* First steps */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=script.service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.9&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
|icon url=https://raw.githubusercontent.com/KenV99/script.service.kodi.callbacks/master/icon.png}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Page content goes here --&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&amp;lt;s&amp;gt;The script is not currently available via the official repo but has been submitted as of 27-02-2016.&amp;lt;/s&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
The addon is now available through the official repo (isengard forward) as of 22-04-2016!!!&amp;lt;br /&amp;gt;&lt;br /&gt;
It has one dependency - the requests module. This should automatically be installed by Kodi.&amp;lt;br /&amp;gt;&lt;br /&gt;
If desired, it can also be downloaded manually copied to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python, script or json-rpc-notify.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http:&lt;br /&gt;
*# Put only the url with port here. Further specification will be done on the events page when invoking this task.&lt;br /&gt;
*# Optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
*# Choose which http request type is desired (most commonly GET or POST).&lt;br /&gt;
*# For POST or PUT, choose what Content-Type you want in the header.&lt;br /&gt;
*# Other CGI query type data (i.e ?var1=x&amp;amp;var2=y) will be done on the events page.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications. This is a json notification receiver event. It is completely separate from the json-rpc-notify TASK which sends notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
*A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
*The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
*Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
*To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
*Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
*If you need to ensure that a space is not split, for a space use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
*Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
*   -Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
*When the task that is being run is an http task using either POST or PUT, anything following double question-mark &amp;quot;??&amp;quot; will be treated as payload.&lt;br /&gt;
*# The ?? will not appear as part of the transmitted url string.&lt;br /&gt;
*# What you put following the ?? should depend on the Content-Type selected for the task on the Tasks settings page.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. See below for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the userdata/addon_data/script.service.kodi.callbacks/lib/usertasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
If you have the [http://addons.kodi.tv/show/script.xbmc.debug.log/ Kodi log uploader addon] installed, then you will see a clickable link to send your log directly from this page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to provide information via a settings page to configure it properly.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: &#039;&#039;userdata/addon_data/script.service.kodi.callbacks/lib/tasks&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example scripts:&#039;&#039;&#039;&lt;br /&gt;
* To have a script execute after Kodi exits on windows while passing pid as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;@echo off&lt;br /&gt;
:loop&lt;br /&gt;
tasklist | find &amp;quot; %1 &amp;quot; &amp;gt;nul&lt;br /&gt;
if not errorlevel 1 (&lt;br /&gt;
    timeout /t 2 &amp;gt;nul&lt;br /&gt;
    goto :loop&lt;br /&gt;
)&lt;br /&gt;
REM Put the code you want to run here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script execute after Kodi exits in other OS&#039;s while passing pid as an argument:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
while kill -0 $1 &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
do&lt;br /&gt;
    sleep 0.2&lt;br /&gt;
done&lt;br /&gt;
# insert your code here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script run as sudo while passing the full path to script as a parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
bash &amp;quot;$*&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If things broke after a new update, please try rebuilding your settings first:&lt;br /&gt;
# Note down your settings&lt;br /&gt;
# On the settings page click &#039;Default&#039; and then click &#039;OK&#039;&lt;br /&gt;
# Rebuid your settings&lt;br /&gt;
# Click OK&lt;br /&gt;
# Restart Kodi&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected after trying the above,&lt;br /&gt;
# From the &#039;General&#039; Settings page:&lt;br /&gt;
## Turn on &#039;Show debugging info in normal log&#039;&lt;br /&gt;
## Click OK&lt;br /&gt;
## Recreate your problem&lt;br /&gt;
## Go back to Settings and on the General page, click to write your settings into the log.&lt;br /&gt;
## Exit Kodi&lt;br /&gt;
# Find your log file: [[Log_file/Advanced#Location|Wiki: Log File Location]]&lt;br /&gt;
# UPLOAD AN &#039;&#039;&#039;ENTIRE&#039;&#039;&#039; COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin]&lt;br /&gt;
# INCLUDE A LINK TO THE LOG IN YOUR POST ON THE FORUM&lt;br /&gt;
&lt;br /&gt;
Please do not turn on Kodi&#039;s debug mode before uploading a log unless asked to do so. This typically just generates more noise in the log, making it harder to pinpoint the problem.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Isengard add-on repository]]&lt;br /&gt;
[[Category:Jarvis add-on repository]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=122634</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=122634"/>
		<updated>2016-04-23T12:31:08Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* First steps */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=script.service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.9&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
|icon url=https://raw.githubusercontent.com/KenV99/script.service.kodi.callbacks/master/icon.png}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Page content goes here --&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&amp;lt;s&amp;gt;The script is not currently available via the official repo but has been submitted as of 27-02-2016.&amp;lt;/s&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
The addon is now available through the official repo (isengard forward) as of 22-04-2016!!!&amp;lt;br /&amp;gt;&lt;br /&gt;
It has one dependency - the requests module. This should automatically be installed by Kodi.&amp;lt;br /&amp;gt;&lt;br /&gt;
If desired, it can also be downloaded manually copied to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python, script or json-rpc-notify.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http:&lt;br /&gt;
*# Put only the url with port here. Further specification will be done on the events page when invoking this task.&lt;br /&gt;
*# Optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
*# Choose which http request type is desired (most commonly GET or POST).&lt;br /&gt;
*# For POST or PUT, choose what Content-Type you want in the header.&lt;br /&gt;
*# Other CGI query type data (i.e ?var1=x&amp;amp;var2=y) will be done on the events page.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications. This is a json notification receiver event. It is completely separate from the json-rpc-notify TASK which sends notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
*A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
*The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
*Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
*To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
*Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
*If you need to ensure that a space is not split, for a space use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
*Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
*   -Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
*When the task that is being run is an http task using either POST or PUT, anything following double question-mark &amp;quot;??&amp;quot; will be treated as payload.&lt;br /&gt;
*# The ?? will not appear as part of the transmitted url string.&lt;br /&gt;
*# What you put following the ?? should depend on the Content-Type selected for the task on the Tasks settings page.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. See below for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the userdata/addon_data/script.service.kodi.callbacks/lib/usertasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
If you have the [http://addons.kodi.tv/show/script.xbmc.debug.log/ Kodi log uploader addon] installed, then you will see a clickable link to send your log directly from this page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to provide information via a settings page to configure it properly.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: &#039;&#039;userdata/addon_data/script.service.kodi.callbacks/lib/tasks&#039;&#039; folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example scripts:&#039;&#039;&#039;&lt;br /&gt;
* To have a script execute after Kodi exits on windows while passing pid as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;@echo off&lt;br /&gt;
:loop&lt;br /&gt;
tasklist | find &amp;quot; %1 &amp;quot; &amp;gt;nul&lt;br /&gt;
if not errorlevel 1 (&lt;br /&gt;
    timeout /t 2 &amp;gt;nul&lt;br /&gt;
    goto :loop&lt;br /&gt;
)&lt;br /&gt;
REM Put the code you want to run here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script execute after Kodi exits in other OS&#039;s while passing pid as an argument:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
while kill -0 $1 &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
do&lt;br /&gt;
    sleep 0.2&lt;br /&gt;
done&lt;br /&gt;
# insert your code here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script run as sudo while passing the full path to script as a parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
bash &amp;quot;$*&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If things broke after a new update, please try rebuilding your settings first:&lt;br /&gt;
# Note down your settings&lt;br /&gt;
# On the settings page click &#039;Default&#039; and then click &#039;OK&#039;&lt;br /&gt;
# Rebuid your settings&lt;br /&gt;
# Click OK&lt;br /&gt;
# Restart Kodi&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected after trying the above,&lt;br /&gt;
# From the &#039;General&#039; Settings page:&lt;br /&gt;
## Turn on &#039;Show debugging info in normal log&#039;&lt;br /&gt;
## Click OK&lt;br /&gt;
## Recreate your problem&lt;br /&gt;
## Go back to Settings and on the General page, click to write your settings into the log.&lt;br /&gt;
## Exit Kodi&lt;br /&gt;
# Find your log file: [[Log_file/Advanced#Location|Wiki: Log File Location]]&lt;br /&gt;
# UPLOAD AN &#039;&#039;&#039;ENTIRE&#039;&#039;&#039; COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin]&lt;br /&gt;
# INCLUDE A LINK TO THE LOG IN YOUR POST ON THE FORUM&lt;br /&gt;
&lt;br /&gt;
Please do not turn on Kodi&#039;s debug mode before uploading a log unless asked to do so. This typically just generates more noise in the log, making it harder to pinpoint the problem.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Isengard add-on repository]]&lt;br /&gt;
[[Category:Jarvis add-on repository]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=122633</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=122633"/>
		<updated>2016-04-23T12:30:12Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Settings - General */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=script.service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.9&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
|icon url=https://raw.githubusercontent.com/KenV99/script.service.kodi.callbacks/master/icon.png}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Page content goes here --&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&amp;lt;s&amp;gt;The script is not currently available via the official repo but has been submitted as of 27-02-2016.&amp;lt;/s&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
The addon is now available through the official repo (isengard forward) as of 22-04-2016!!!&amp;lt;br /&amp;gt;&lt;br /&gt;
It has one dependency - the requests module. This should automatically be installed by Kodi.&amp;lt;br /&amp;gt;&lt;br /&gt;
If desired, it can also be downloaded manually copied to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python, script or json-rpc-notify.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http:&lt;br /&gt;
*# Put only the url with port here. Further specification will be done on the events page when invoking this task.&lt;br /&gt;
*# Optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
*# Choose which http request type is desired (most commonly GET or POST).&lt;br /&gt;
*# For POST or PUT, choose what Content-Type you want in the header.&lt;br /&gt;
*# Other CGI query type data (i.e ?var1=x&amp;amp;var2=y) will be done on the events page.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications. This is a json notification receiver event. It is completely separate from the json-rpc-notify TASK which sends notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
*A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
*The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
*Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
*To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
*Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
*If you need to ensure that a space is not split, for a space use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
*Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
*   -Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
*When the task that is being run is an http task using either POST or PUT, anything following double question-mark &amp;quot;??&amp;quot; will be treated as payload.&lt;br /&gt;
*# The ?? will not appear as part of the transmitted url string.&lt;br /&gt;
*# What you put following the ?? should depend on the Content-Type selected for the task on the Tasks settings page.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. See below for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the userdata/addon_data/script.service.kodi.callbacks/lib/usertasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
If you have the [http://addons.kodi.tv/show/script.xbmc.debug.log/ Kodi log uploader addon] installed, then you will see a clickable link to send your log directly from this page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to provide information via a settings page to configure it properly.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example scripts:&#039;&#039;&#039;&lt;br /&gt;
* To have a script execute after Kodi exits on windows while passing pid as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;@echo off&lt;br /&gt;
:loop&lt;br /&gt;
tasklist | find &amp;quot; %1 &amp;quot; &amp;gt;nul&lt;br /&gt;
if not errorlevel 1 (&lt;br /&gt;
    timeout /t 2 &amp;gt;nul&lt;br /&gt;
    goto :loop&lt;br /&gt;
)&lt;br /&gt;
REM Put the code you want to run here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script execute after Kodi exits in other OS&#039;s while passing pid as an argument:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
while kill -0 $1 &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
do&lt;br /&gt;
    sleep 0.2&lt;br /&gt;
done&lt;br /&gt;
# insert your code here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script run as sudo while passing the full path to script as a parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
bash &amp;quot;$*&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If things broke after a new update, please try rebuilding your settings first:&lt;br /&gt;
# Note down your settings&lt;br /&gt;
# On the settings page click &#039;Default&#039; and then click &#039;OK&#039;&lt;br /&gt;
# Rebuid your settings&lt;br /&gt;
# Click OK&lt;br /&gt;
# Restart Kodi&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected after trying the above,&lt;br /&gt;
# From the &#039;General&#039; Settings page:&lt;br /&gt;
## Turn on &#039;Show debugging info in normal log&#039;&lt;br /&gt;
## Click OK&lt;br /&gt;
## Recreate your problem&lt;br /&gt;
## Go back to Settings and on the General page, click to write your settings into the log.&lt;br /&gt;
## Exit Kodi&lt;br /&gt;
# Find your log file: [[Log_file/Advanced#Location|Wiki: Log File Location]]&lt;br /&gt;
# UPLOAD AN &#039;&#039;&#039;ENTIRE&#039;&#039;&#039; COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin]&lt;br /&gt;
# INCLUDE A LINK TO THE LOG IN YOUR POST ON THE FORUM&lt;br /&gt;
&lt;br /&gt;
Please do not turn on Kodi&#039;s debug mode before uploading a log unless asked to do so. This typically just generates more noise in the log, making it harder to pinpoint the problem.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Isengard add-on repository]]&lt;br /&gt;
[[Category:Jarvis add-on repository]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=122632</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=122632"/>
		<updated>2016-04-23T12:10:56Z</updated>

		<summary type="html">&lt;p&gt;KenV99: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=script.service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.9&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
|icon url=https://raw.githubusercontent.com/KenV99/script.service.kodi.callbacks/master/icon.png}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Page content goes here --&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&amp;lt;s&amp;gt;The script is not currently available via the official repo but has been submitted as of 27-02-2016.&amp;lt;/s&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
The addon is now available through the official repo (isengard forward) as of 22-04-2016!!!&amp;lt;br /&amp;gt;&lt;br /&gt;
It has one dependency - the requests module. This should automatically be installed by Kodi.&amp;lt;br /&amp;gt;&lt;br /&gt;
If desired, it can also be downloaded manually copied to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python, script or json-rpc-notify.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http:&lt;br /&gt;
*# Put only the url with port here. Further specification will be done on the events page when invoking this task.&lt;br /&gt;
*# Optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
*# Choose which http request type is desired (most commonly GET or POST).&lt;br /&gt;
*# For POST or PUT, choose what Content-Type you want in the header.&lt;br /&gt;
*# Other CGI query type data (i.e ?var1=x&amp;amp;var2=y) will be done on the events page.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications. This is a json notification receiver event. It is completely separate from the json-rpc-notify TASK which sends notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
*A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
*The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
*Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
*To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
*Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
*If you need to ensure that a space is not split, for a space use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
*Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
*   -Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
*When the task that is being run is an http task using either POST or PUT, anything following double question-mark &amp;quot;??&amp;quot; will be treated as payload.&lt;br /&gt;
*# The ?? will not appear as part of the transmitted url string.&lt;br /&gt;
*# What you put following the ?? should depend on the Content-Type selected for the task on the Tasks settings page.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. See below for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
If you have the [http://addons.kodi.tv/show/script.xbmc.debug.log/ Kodi log uploader addon] installed, then you will see a clickable link to send your log directly from this page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to provide information via a settings page to configure it properly.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example scripts:&#039;&#039;&#039;&lt;br /&gt;
* To have a script execute after Kodi exits on windows while passing pid as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;@echo off&lt;br /&gt;
:loop&lt;br /&gt;
tasklist | find &amp;quot; %1 &amp;quot; &amp;gt;nul&lt;br /&gt;
if not errorlevel 1 (&lt;br /&gt;
    timeout /t 2 &amp;gt;nul&lt;br /&gt;
    goto :loop&lt;br /&gt;
)&lt;br /&gt;
REM Put the code you want to run here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script execute after Kodi exits in other OS&#039;s while passing pid as an argument:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
while kill -0 $1 &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
do&lt;br /&gt;
    sleep 0.2&lt;br /&gt;
done&lt;br /&gt;
# insert your code here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script run as sudo while passing the full path to script as a parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
bash &amp;quot;$*&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If things broke after a new update, please try rebuilding your settings first:&lt;br /&gt;
# Note down your settings&lt;br /&gt;
# On the settings page click &#039;Default&#039; and then click &#039;OK&#039;&lt;br /&gt;
# Rebuid your settings&lt;br /&gt;
# Click OK&lt;br /&gt;
# Restart Kodi&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected after trying the above,&lt;br /&gt;
# From the &#039;General&#039; Settings page:&lt;br /&gt;
## Turn on &#039;Show debugging info in normal log&#039;&lt;br /&gt;
## Click OK&lt;br /&gt;
## Recreate your problem&lt;br /&gt;
## Go back to Settings and on the General page, click to write your settings into the log.&lt;br /&gt;
## Exit Kodi&lt;br /&gt;
# Find your log file: [[Log_file/Advanced#Location|Wiki: Log File Location]]&lt;br /&gt;
# UPLOAD AN &#039;&#039;&#039;ENTIRE&#039;&#039;&#039; COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin]&lt;br /&gt;
# INCLUDE A LINK TO THE LOG IN YOUR POST ON THE FORUM&lt;br /&gt;
&lt;br /&gt;
Please do not turn on Kodi&#039;s debug mode before uploading a log unless asked to do so. This typically just generates more noise in the log, making it harder to pinpoint the problem.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Isengard add-on repository]]&lt;br /&gt;
[[Category:Jarvis add-on repository]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=122631</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=122631"/>
		<updated>2016-04-23T12:00:24Z</updated>

		<summary type="html">&lt;p&gt;KenV99: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=script.service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.9&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
|icon url=https://raw.githubusercontent.com/KenV99/script.service.kodi.callbacks/master/icon.png}}&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&amp;lt;s&amp;gt;The script is not currently available via the official repo but has been submitted as of 27-02-2016.&amp;lt;/s&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
The addon is now available through the official repo (isengard forward) as of 22-04-2016!!!&amp;lt;br /&amp;gt;&lt;br /&gt;
It has one dependency - the requests module. This should automatically be installed by Kodi.&amp;lt;br /&amp;gt;&lt;br /&gt;
If desired, it can also be downloaded manually copied to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python, script or json-rpc-notify.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http:&lt;br /&gt;
*# Put only the url with port here. Further specification will be done on the events page when invoking this task.&lt;br /&gt;
*# Optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
*# Choose which http request type is desired (most commonly GET or POST).&lt;br /&gt;
*# For POST or PUT, choose what Content-Type you want in the header.&lt;br /&gt;
*# Other CGI query type data (i.e ?var1=x&amp;amp;var2=y) will be done on the events page.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications. This is a json notification receiver event. It is completely separate from the json-rpc-notify TASK which sends notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
*A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
*The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
*Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
*To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
*Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
*If you need to ensure that a space is not split, for a space use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
*Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
*   -Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
*When the task that is being run is an http task using either POST or PUT, anything following double question-mark &amp;quot;??&amp;quot; will be treated as payload.&lt;br /&gt;
*# The ?? will not appear as part of the transmitted url string.&lt;br /&gt;
*# What you put following the ?? should depend on the Content-Type selected for the task on the Tasks settings page.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. See below for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
If you have the [http://addons.kodi.tv/show/script.xbmc.debug.log/ Kodi log uploader addon] installed, then you will see a clickable link to send your log directly from this page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to provide information via a settings page to configure it properly.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example scripts:&#039;&#039;&#039;&lt;br /&gt;
* To have a script execute after Kodi exits on windows while passing pid as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;@echo off&lt;br /&gt;
:loop&lt;br /&gt;
tasklist | find &amp;quot; %1 &amp;quot; &amp;gt;nul&lt;br /&gt;
if not errorlevel 1 (&lt;br /&gt;
    timeout /t 2 &amp;gt;nul&lt;br /&gt;
    goto :loop&lt;br /&gt;
)&lt;br /&gt;
REM Put the code you want to run here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script execute after Kodi exits in other OS&#039;s while passing pid as an argument:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
while kill -0 $1 &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
do&lt;br /&gt;
    sleep 0.2&lt;br /&gt;
done&lt;br /&gt;
# insert your code here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script run as sudo while passing the full path to script as a parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
bash &amp;quot;$*&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If things broke after a new update, please try rebuilding your settings first:&lt;br /&gt;
# Note down your settings&lt;br /&gt;
# On the settings page click &#039;Default&#039; and then click &#039;OK&#039;&lt;br /&gt;
# Rebuid your settings&lt;br /&gt;
# Click OK&lt;br /&gt;
# Restart Kodi&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected after trying the above,&lt;br /&gt;
# From the &#039;General&#039; Settings page:&lt;br /&gt;
## Turn on &#039;Show debugging info in normal log&#039;&lt;br /&gt;
## Click OK&lt;br /&gt;
## Recreate your problem&lt;br /&gt;
## Go back to Settings and on the General page, click to write your settings into the log.&lt;br /&gt;
## Exit Kodi&lt;br /&gt;
# Find your log file: [[Log_file/Advanced#Location|Wiki: Log File Location]]&lt;br /&gt;
# UPLOAD AN &#039;&#039;&#039;ENTIRE&#039;&#039;&#039; COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin]&lt;br /&gt;
# INCLUDE A LINK TO THE LOG IN YOUR POST ON THE FORUM&lt;br /&gt;
&lt;br /&gt;
Please do not turn on Kodi&#039;s debug mode before uploading a log unless asked to do so. This typically just generates more noise in the log, making it harder to pinpoint the problem.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Isengard add-on repository]]&lt;br /&gt;
[[Category:Jarvis add-on repository]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=122630</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=122630"/>
		<updated>2016-04-23T11:59:20Z</updated>

		<summary type="html">&lt;p&gt;KenV99: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=script.service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.9&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
|icon url=http://mirrors.kodi.tv/addons/isengard/script.service.kodi.callbacks/icon.jpg}}&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&amp;lt;s&amp;gt;The script is not currently available via the official repo but has been submitted as of 27-02-2016.&amp;lt;/s&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
The addon is now available through the official repo (isengard forward) as of 22-04-2016!!!&amp;lt;br /&amp;gt;&lt;br /&gt;
It has one dependency - the requests module. This should automatically be installed by Kodi.&amp;lt;br /&amp;gt;&lt;br /&gt;
If desired, it can also be downloaded manually copied to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python, script or json-rpc-notify.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http:&lt;br /&gt;
*# Put only the url with port here. Further specification will be done on the events page when invoking this task.&lt;br /&gt;
*# Optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
*# Choose which http request type is desired (most commonly GET or POST).&lt;br /&gt;
*# For POST or PUT, choose what Content-Type you want in the header.&lt;br /&gt;
*# Other CGI query type data (i.e ?var1=x&amp;amp;var2=y) will be done on the events page.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications. This is a json notification receiver event. It is completely separate from the json-rpc-notify TASK which sends notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
*A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
*The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
*Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
*To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
*Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
*If you need to ensure that a space is not split, for a space use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
*Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
*   -Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
*When the task that is being run is an http task using either POST or PUT, anything following double question-mark &amp;quot;??&amp;quot; will be treated as payload.&lt;br /&gt;
*# The ?? will not appear as part of the transmitted url string.&lt;br /&gt;
*# What you put following the ?? should depend on the Content-Type selected for the task on the Tasks settings page.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. See below for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
If you have the [http://addons.kodi.tv/show/script.xbmc.debug.log/ Kodi log uploader addon] installed, then you will see a clickable link to send your log directly from this page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to provide information via a settings page to configure it properly.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example scripts:&#039;&#039;&#039;&lt;br /&gt;
* To have a script execute after Kodi exits on windows while passing pid as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;@echo off&lt;br /&gt;
:loop&lt;br /&gt;
tasklist | find &amp;quot; %1 &amp;quot; &amp;gt;nul&lt;br /&gt;
if not errorlevel 1 (&lt;br /&gt;
    timeout /t 2 &amp;gt;nul&lt;br /&gt;
    goto :loop&lt;br /&gt;
)&lt;br /&gt;
REM Put the code you want to run here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script execute after Kodi exits in other OS&#039;s while passing pid as an argument:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
while kill -0 $1 &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
do&lt;br /&gt;
    sleep 0.2&lt;br /&gt;
done&lt;br /&gt;
# insert your code here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script run as sudo while passing the full path to script as a parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
bash &amp;quot;$*&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If things broke after a new update, please try rebuilding your settings first:&lt;br /&gt;
# Note down your settings&lt;br /&gt;
# On the settings page click &#039;Default&#039; and then click &#039;OK&#039;&lt;br /&gt;
# Rebuid your settings&lt;br /&gt;
# Click OK&lt;br /&gt;
# Restart Kodi&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected after trying the above,&lt;br /&gt;
# From the &#039;General&#039; Settings page:&lt;br /&gt;
## Turn on &#039;Show debugging info in normal log&#039;&lt;br /&gt;
## Click OK&lt;br /&gt;
## Recreate your problem&lt;br /&gt;
## Go back to Settings and on the General page, click to write your settings into the log.&lt;br /&gt;
## Exit Kodi&lt;br /&gt;
# Find your log file: [[Log_file/Advanced#Location|Wiki: Log File Location]]&lt;br /&gt;
# UPLOAD AN &#039;&#039;&#039;ENTIRE&#039;&#039;&#039; COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin]&lt;br /&gt;
# INCLUDE A LINK TO THE LOG IN YOUR POST ON THE FORUM&lt;br /&gt;
&lt;br /&gt;
Please do not turn on Kodi&#039;s debug mode before uploading a log unless asked to do so. This typically just generates more noise in the log, making it harder to pinpoint the problem.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Isengard add-on repository]]&lt;br /&gt;
[[Category:Jarvis add-on repository]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=122629</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=122629"/>
		<updated>2016-04-23T11:56:16Z</updated>

		<summary type="html">&lt;p&gt;KenV99: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=script.service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.9&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
|icon url=http://mirrors.kodi.tv/addons/isengard/script.service.kodi.callbacks/icon.jpg&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&amp;lt;s&amp;gt;The script is not currently available via the official repo but has been submitted as of 27-02-2016.&amp;lt;/s&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
The addon is now available through the official repo (isengard forward) as of 22-04-2016!!!&amp;lt;br /&amp;gt;&lt;br /&gt;
It has one dependency - the requests module. This should automatically be installed by Kodi.&amp;lt;br /&amp;gt;&lt;br /&gt;
If desired, it can also be downloaded manually copied to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python, script or json-rpc-notify.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http:&lt;br /&gt;
*# Put only the url with port here. Further specification will be done on the events page when invoking this task.&lt;br /&gt;
*# Optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
*# Choose which http request type is desired (most commonly GET or POST).&lt;br /&gt;
*# For POST or PUT, choose what Content-Type you want in the header.&lt;br /&gt;
*# Other CGI query type data (i.e ?var1=x&amp;amp;var2=y) will be done on the events page.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications. This is a json notification receiver event. It is completely separate from the json-rpc-notify TASK which sends notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
*A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
*The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
*Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
*To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
*Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
*If you need to ensure that a space is not split, for a space use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
*Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
*   -Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
*When the task that is being run is an http task using either POST or PUT, anything following double question-mark &amp;quot;??&amp;quot; will be treated as payload.&lt;br /&gt;
*# The ?? will not appear as part of the transmitted url string.&lt;br /&gt;
*# What you put following the ?? should depend on the Content-Type selected for the task on the Tasks settings page.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. See below for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
If you have the [http://addons.kodi.tv/show/script.xbmc.debug.log/ Kodi log uploader addon] installed, then you will see a clickable link to send your log directly from this page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to provide information via a settings page to configure it properly.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example scripts:&#039;&#039;&#039;&lt;br /&gt;
* To have a script execute after Kodi exits on windows while passing pid as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;@echo off&lt;br /&gt;
:loop&lt;br /&gt;
tasklist | find &amp;quot; %1 &amp;quot; &amp;gt;nul&lt;br /&gt;
if not errorlevel 1 (&lt;br /&gt;
    timeout /t 2 &amp;gt;nul&lt;br /&gt;
    goto :loop&lt;br /&gt;
)&lt;br /&gt;
REM Put the code you want to run here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script execute after Kodi exits in other OS&#039;s while passing pid as an argument:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
while kill -0 $1 &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
do&lt;br /&gt;
    sleep 0.2&lt;br /&gt;
done&lt;br /&gt;
# insert your code here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script run as sudo while passing the full path to script as a parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
bash &amp;quot;$*&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If things broke after a new update, please try rebuilding your settings first:&lt;br /&gt;
# Note down your settings&lt;br /&gt;
# On the settings page click &#039;Default&#039; and then click &#039;OK&#039;&lt;br /&gt;
# Rebuid your settings&lt;br /&gt;
# Click OK&lt;br /&gt;
# Restart Kodi&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected after trying the above,&lt;br /&gt;
# From the &#039;General&#039; Settings page:&lt;br /&gt;
## Turn on &#039;Show debugging info in normal log&#039;&lt;br /&gt;
## Click OK&lt;br /&gt;
## Recreate your problem&lt;br /&gt;
## Go back to Settings and on the General page, click to write your settings into the log.&lt;br /&gt;
## Exit Kodi&lt;br /&gt;
# Find your log file: [[Log_file/Advanced#Location|Wiki: Log File Location]]&lt;br /&gt;
# UPLOAD AN &#039;&#039;&#039;ENTIRE&#039;&#039;&#039; COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin]&lt;br /&gt;
# INCLUDE A LINK TO THE LOG IN YOUR POST ON THE FORUM&lt;br /&gt;
&lt;br /&gt;
Please do not turn on Kodi&#039;s debug mode before uploading a log unless asked to do so. This typically just generates more noise in the log, making it harder to pinpoint the problem.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Isengard add-on repository]]&lt;br /&gt;
[[Category:Jarvis add-on repository]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=122628</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=122628"/>
		<updated>2016-04-23T11:47:59Z</updated>

		<summary type="html">&lt;p&gt;KenV99: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=script.service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.9&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&amp;lt;s&amp;gt;The script is not currently available via the official repo but has been submitted as of 27-02-2016.&amp;lt;/s&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
The addon is now available through the official repo (isengard forward) as of 22-04-2016!!!&amp;lt;br /&amp;gt;&lt;br /&gt;
It has one dependency - the requests module. This should automatically be installed by Kodi.&amp;lt;br /&amp;gt;&lt;br /&gt;
If desired, it can also be downloaded manually copied to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python, script or json-rpc-notify.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http:&lt;br /&gt;
*# Put only the url with port here. Further specification will be done on the events page when invoking this task.&lt;br /&gt;
*# Optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
*# Choose which http request type is desired (most commonly GET or POST).&lt;br /&gt;
*# For POST or PUT, choose what Content-Type you want in the header.&lt;br /&gt;
*# Other CGI query type data (i.e ?var1=x&amp;amp;var2=y) will be done on the events page.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications. This is a json notification receiver event. It is completely separate from the json-rpc-notify TASK which sends notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
*A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
*The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
*Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
*To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
*Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
*If you need to ensure that a space is not split, for a space use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
*Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
*   -Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
*When the task that is being run is an http task using either POST or PUT, anything following double question-mark &amp;quot;??&amp;quot; will be treated as payload.&lt;br /&gt;
*# The ?? will not appear as part of the transmitted url string.&lt;br /&gt;
*# What you put following the ?? should depend on the Content-Type selected for the task on the Tasks settings page.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. See below for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
If you have the [http://addons.kodi.tv/show/script.xbmc.debug.log/ Kodi log uploader addon] installed, then you will see a clickable link to send your log directly from this page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to provide information via a settings page to configure it properly.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example scripts:&#039;&#039;&#039;&lt;br /&gt;
* To have a script execute after Kodi exits on windows while passing pid as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;@echo off&lt;br /&gt;
:loop&lt;br /&gt;
tasklist | find &amp;quot; %1 &amp;quot; &amp;gt;nul&lt;br /&gt;
if not errorlevel 1 (&lt;br /&gt;
    timeout /t 2 &amp;gt;nul&lt;br /&gt;
    goto :loop&lt;br /&gt;
)&lt;br /&gt;
REM Put the code you want to run here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script execute after Kodi exits in other OS&#039;s while passing pid as an argument:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
while kill -0 $1 &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
do&lt;br /&gt;
    sleep 0.2&lt;br /&gt;
done&lt;br /&gt;
# insert your code here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script run as sudo while passing the full path to script as a parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
bash &amp;quot;$*&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If things broke after a new update, please try rebuilding your settings first:&lt;br /&gt;
# Note down your settings&lt;br /&gt;
# On the settings page click &#039;Default&#039; and then click &#039;OK&#039;&lt;br /&gt;
# Rebuid your settings&lt;br /&gt;
# Click OK&lt;br /&gt;
# Restart Kodi&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected after trying the above,&lt;br /&gt;
# From the &#039;General&#039; Settings page:&lt;br /&gt;
## Turn on &#039;Show debugging info in normal log&#039;&lt;br /&gt;
## Click OK&lt;br /&gt;
## Recreate your problem&lt;br /&gt;
## Go back to Settings and on the General page, click to write your settings into the log.&lt;br /&gt;
## Exit Kodi&lt;br /&gt;
# Find your log file: [[Log_file/Advanced#Location|Wiki: Log File Location]]&lt;br /&gt;
# UPLOAD AN &#039;&#039;&#039;ENTIRE&#039;&#039;&#039; COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin]&lt;br /&gt;
# INCLUDE A LINK TO THE LOG IN YOUR POST ON THE FORUM&lt;br /&gt;
&lt;br /&gt;
Please do not turn on Kodi&#039;s debug mode before uploading a log unless asked to do so. This typically just generates more noise in the log, making it harder to pinpoint the problem.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=122627</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=122627"/>
		<updated>2016-04-23T11:33:25Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Settings - Events */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&amp;lt;s&amp;gt;The script is not currently available via the official repo but has been submitted as of 27-02-2016.&amp;lt;/s&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
The addon is now available through the official repo (isengard forward) as of 22-04-2016!!!&amp;lt;br /&amp;gt;&lt;br /&gt;
It has one dependency - the requests module. This should automatically be installed by Kodi.&amp;lt;br /&amp;gt;&lt;br /&gt;
If desired, it can also be downloaded manually copied to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python, script or json-rpc-notify.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http:&lt;br /&gt;
*# Put only the url with port here. Further specification will be done on the events page when invoking this task.&lt;br /&gt;
*# Optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
*# Choose which http request type is desired (most commonly GET or POST).&lt;br /&gt;
*# For POST or PUT, choose what Content-Type you want in the header.&lt;br /&gt;
*# Other CGI query type data (i.e ?var1=x&amp;amp;var2=y) will be done on the events page.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications. This is a json notification receiver event. It is completely separate from the json-rpc-notify TASK which sends notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
*A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
*The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
*Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
*To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
*Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
*If you need to ensure that a space is not split, for a space use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
*Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
*   -Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
*When the task that is being run is an http task using either POST or PUT, anything following double question-mark &amp;quot;??&amp;quot; will be treated as payload.&lt;br /&gt;
*# The ?? will not appear as part of the transmitted url string.&lt;br /&gt;
*# What you put following the ?? should depend on the Content-Type selected for the task on the Tasks settings page.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. See below for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
If you have the [http://addons.kodi.tv/show/script.xbmc.debug.log/ Kodi log uploader addon] installed, then you will see a clickable link to send your log directly from this page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to provide information via a settings page to configure it properly.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example scripts:&#039;&#039;&#039;&lt;br /&gt;
* To have a script execute after Kodi exits on windows while passing pid as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;@echo off&lt;br /&gt;
:loop&lt;br /&gt;
tasklist | find &amp;quot; %1 &amp;quot; &amp;gt;nul&lt;br /&gt;
if not errorlevel 1 (&lt;br /&gt;
    timeout /t 2 &amp;gt;nul&lt;br /&gt;
    goto :loop&lt;br /&gt;
)&lt;br /&gt;
REM Put the code you want to run here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script execute after Kodi exits in other OS&#039;s while passing pid as an argument:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
while kill -0 $1 &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
do&lt;br /&gt;
    sleep 0.2&lt;br /&gt;
done&lt;br /&gt;
# insert your code here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script run as sudo while passing the full path to script as a parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
bash &amp;quot;$*&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If things broke after a new update, please try rebuilding your settings first:&lt;br /&gt;
# Note down your settings&lt;br /&gt;
# On the settings page click &#039;Default&#039; and then click &#039;OK&#039;&lt;br /&gt;
# Rebuid your settings&lt;br /&gt;
# Click OK&lt;br /&gt;
# Restart Kodi&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected after trying the above,&lt;br /&gt;
# From the &#039;General&#039; Settings page:&lt;br /&gt;
## Turn on &#039;Show debugging info in normal log&#039;&lt;br /&gt;
## Click OK&lt;br /&gt;
## Recreate your problem&lt;br /&gt;
## Go back to Settings and on the General page, click to write your settings into the log.&lt;br /&gt;
## Exit Kodi&lt;br /&gt;
# Find your log file: [[Log_file/Advanced#Location|Wiki: Log File Location]]&lt;br /&gt;
# UPLOAD AN &#039;&#039;&#039;ENTIRE&#039;&#039;&#039; COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin]&lt;br /&gt;
# INCLUDE A LINK TO THE LOG IN YOUR POST ON THE FORUM&lt;br /&gt;
&lt;br /&gt;
Please do not turn on Kodi&#039;s debug mode before uploading a log unless asked to do so. This typically just generates more noise in the log, making it harder to pinpoint the problem.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=122626</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=122626"/>
		<updated>2016-04-23T11:31:57Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&amp;lt;s&amp;gt;The script is not currently available via the official repo but has been submitted as of 27-02-2016.&amp;lt;/s&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
The addon is now available through the official repo (isengard forward) as of 22-04-2016!!!&amp;lt;br /&amp;gt;&lt;br /&gt;
It has one dependency - the requests module. This should automatically be installed by Kodi.&amp;lt;br /&amp;gt;&lt;br /&gt;
If desired, it can also be downloaded manually copied to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python, script or json-rpc-notify.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http:&lt;br /&gt;
*# Put only the url with port here. Further specification will be done on the events page when invoking this task.&lt;br /&gt;
*# Optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
*# Choose which http request type is desired (most commonly GET or POST).&lt;br /&gt;
*# For POST or PUT, choose what Content-Type you want in the header.&lt;br /&gt;
*# Other CGI query type data (i.e ?var1=x&amp;amp;var2=y) will be done on the events page.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications. This is a json notification receiver event. It is completely separate from the json-rpc-notify TASK which sends notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
*A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
*The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
*Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
*To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
*Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
*If you need to ensure that a space is not split, for a space use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
*Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
*   -Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
*When the task that is being run is an http task using either POST or PUT, anything following double question-mark &amp;quot;??&amp;quot; will be treated as payload.&lt;br /&gt;
*# The ?? will not appear as part of the transmitted url string.&lt;br /&gt;
*# What you put following the ?? should depend on the Content-Type selected for the task on the Tasks settings page.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
If you have the [http://addons.kodi.tv/show/script.xbmc.debug.log/ Kodi log uploader addon] installed, then you will see a clickable link to send your log directly from this page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to provide information via a settings page to configure it properly.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example scripts:&#039;&#039;&#039;&lt;br /&gt;
* To have a script execute after Kodi exits on windows while passing pid as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;@echo off&lt;br /&gt;
:loop&lt;br /&gt;
tasklist | find &amp;quot; %1 &amp;quot; &amp;gt;nul&lt;br /&gt;
if not errorlevel 1 (&lt;br /&gt;
    timeout /t 2 &amp;gt;nul&lt;br /&gt;
    goto :loop&lt;br /&gt;
)&lt;br /&gt;
REM Put the code you want to run here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script execute after Kodi exits in other OS&#039;s while passing pid as an argument:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
while kill -0 $1 &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
do&lt;br /&gt;
    sleep 0.2&lt;br /&gt;
done&lt;br /&gt;
# insert your code here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script run as sudo while passing the full path to script as a parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
bash &amp;quot;$*&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If things broke after a new update, please try rebuilding your settings first:&lt;br /&gt;
# Note down your settings&lt;br /&gt;
# On the settings page click &#039;Default&#039; and then click &#039;OK&#039;&lt;br /&gt;
# Rebuid your settings&lt;br /&gt;
# Click OK&lt;br /&gt;
# Restart Kodi&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected after trying the above,&lt;br /&gt;
# From the &#039;General&#039; Settings page:&lt;br /&gt;
## Turn on &#039;Show debugging info in normal log&#039;&lt;br /&gt;
## Click OK&lt;br /&gt;
## Recreate your problem&lt;br /&gt;
## Go back to Settings and on the General page, click to write your settings into the log.&lt;br /&gt;
## Exit Kodi&lt;br /&gt;
# Find your log file: [[Log_file/Advanced#Location|Wiki: Log File Location]]&lt;br /&gt;
# UPLOAD AN &#039;&#039;&#039;ENTIRE&#039;&#039;&#039; COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin]&lt;br /&gt;
# INCLUDE A LINK TO THE LOG IN YOUR POST ON THE FORUM&lt;br /&gt;
&lt;br /&gt;
Please do not turn on Kodi&#039;s debug mode before uploading a log unless asked to do so. This typically just generates more noise in the log, making it harder to pinpoint the problem.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=122625</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=122625"/>
		<updated>2016-04-23T11:29:50Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&amp;lt;s&amp;gt;The script is not currently available via the official repo but has been submitted as of 27-02-2016.&amp;lt;/s&amp;gt;&lt;br /&gt;
The addon is now available through the official repo (isengard forward) as of 22-04-2016!!!&lt;br /&gt;
If desired, it can also be downloaded manually copied to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python, script or json-rpc-notify.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http:&lt;br /&gt;
*# Put only the url with port here. Further specification will be done on the events page when invoking this task.&lt;br /&gt;
*# Optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
*# Choose which http request type is desired (most commonly GET or POST).&lt;br /&gt;
*# For POST or PUT, choose what Content-Type you want in the header.&lt;br /&gt;
*# Other CGI query type data (i.e ?var1=x&amp;amp;var2=y) will be done on the events page.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications. This is a json notification receiver event. It is completely separate from the json-rpc-notify TASK which sends notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
*A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
*The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
*Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
*To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
*Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
*If you need to ensure that a space is not split, for a space use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
*Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
*   -Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
*When the task that is being run is an http task using either POST or PUT, anything following double question-mark &amp;quot;??&amp;quot; will be treated as payload.&lt;br /&gt;
*# The ?? will not appear as part of the transmitted url string.&lt;br /&gt;
*# What you put following the ?? should depend on the Content-Type selected for the task on the Tasks settings page.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
If you have the [http://addons.kodi.tv/show/script.xbmc.debug.log/ Kodi log uploader addon] installed, then you will see a clickable link to send your log directly from this page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to provide information via a settings page to configure it properly.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example scripts:&#039;&#039;&#039;&lt;br /&gt;
* To have a script execute after Kodi exits on windows while passing pid as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;@echo off&lt;br /&gt;
:loop&lt;br /&gt;
tasklist | find &amp;quot; %1 &amp;quot; &amp;gt;nul&lt;br /&gt;
if not errorlevel 1 (&lt;br /&gt;
    timeout /t 2 &amp;gt;nul&lt;br /&gt;
    goto :loop&lt;br /&gt;
)&lt;br /&gt;
REM Put the code you want to run here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script execute after Kodi exits in other OS&#039;s while passing pid as an argument:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
while kill -0 $1 &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
do&lt;br /&gt;
    sleep 0.2&lt;br /&gt;
done&lt;br /&gt;
# insert your code here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script run as sudo while passing the full path to script as a parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
bash &amp;quot;$*&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If things broke after a new update, please try rebuilding your settings first:&lt;br /&gt;
# Note down your settings&lt;br /&gt;
# On the settings page click &#039;Default&#039; and then click &#039;OK&#039;&lt;br /&gt;
# Rebuid your settings&lt;br /&gt;
# Click OK&lt;br /&gt;
# Restart Kodi&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected after trying the above,&lt;br /&gt;
# From the &#039;General&#039; Settings page:&lt;br /&gt;
## Turn on &#039;Show debugging info in normal log&#039;&lt;br /&gt;
## Click OK&lt;br /&gt;
## Recreate your problem&lt;br /&gt;
## Go back to Settings and on the General page, click to write your settings into the log.&lt;br /&gt;
## Exit Kodi&lt;br /&gt;
# Find your log file: [[Log_file/Advanced#Location|Wiki: Log File Location]]&lt;br /&gt;
# UPLOAD AN &#039;&#039;&#039;ENTIRE&#039;&#039;&#039; COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin]&lt;br /&gt;
# INCLUDE A LINK TO THE LOG IN YOUR POST ON THE FORUM&lt;br /&gt;
&lt;br /&gt;
Please do not turn on Kodi&#039;s debug mode before uploading a log unless asked to do so. This typically just generates more noise in the log, making it harder to pinpoint the problem.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=121728</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=121728"/>
		<updated>2016-04-20T19:57:07Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python, script or json-rpc-notify.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http:&lt;br /&gt;
*# Put only the url with port here. Further specification will be done on the events page when invoking this task.&lt;br /&gt;
*# Optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
*# Choose which http request type is desired (most commonly GET or POST).&lt;br /&gt;
*# For POST or PUT, choose what Content-Type you want in the header.&lt;br /&gt;
*# Other CGI query type data (i.e ?var1=x&amp;amp;var2=y) will be done on the events page.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications. This is a json notification receiver event. It is completely separate from the json-rpc-notify TASK which sends notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
*A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
*The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
*Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
*To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
*Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
*If you need to ensure that a space is not split, for a space use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
*Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
*   -Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
*When the task that is being run is an http task using either POST or PUT, anything following double question-mark &amp;quot;??&amp;quot; will be treated as payload.&lt;br /&gt;
*# The ?? will not appear as part of the transmitted url string.&lt;br /&gt;
*# What you put following the ?? should depend on the Content-Type selected for the task on the Tasks settings page.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
If you have the [http://addons.kodi.tv/show/script.xbmc.debug.log/ Kodi log uploader addon] installed, then you will see a clickable link to send your log directly from this page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to provide information via a settings page to configure it properly.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Example scripts:&#039;&#039;&#039;&lt;br /&gt;
* To have a script execute after Kodi exits on windows while passing pid as an argument:&lt;br /&gt;
&amp;lt;pre&amp;gt;@echo off&lt;br /&gt;
:loop&lt;br /&gt;
tasklist | find &amp;quot; %1 &amp;quot; &amp;gt;nul&lt;br /&gt;
if not errorlevel 1 (&lt;br /&gt;
    timeout /t 2 &amp;gt;nul&lt;br /&gt;
    goto :loop&lt;br /&gt;
)&lt;br /&gt;
REM Put the code you want to run here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script execute after Kodi exits in other OS&#039;s while passing pid as an argument:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
while kill -0 $1 &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
do&lt;br /&gt;
    sleep 0.2&lt;br /&gt;
done&lt;br /&gt;
# insert your code here&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* To have a script run as sudo while passing the full path to script as a parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;#!/usr/bin/env bash&lt;br /&gt;
bash &amp;quot;$*&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If things broke after a new update, please try rebuilding your settings first:&lt;br /&gt;
# Note down your settings&lt;br /&gt;
# On the settings page click &#039;Default&#039; and then click &#039;OK&#039;&lt;br /&gt;
# Rebuid your settings&lt;br /&gt;
# Click OK&lt;br /&gt;
# Restart Kodi&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected after trying the above,&lt;br /&gt;
# From the &#039;General&#039; Settings page:&lt;br /&gt;
## Turn on &#039;Show debugging info in normal log&#039;&lt;br /&gt;
## Click OK&lt;br /&gt;
## Recreate your problem&lt;br /&gt;
## Go back to Settings and on the General page, click to write your settings into the log.&lt;br /&gt;
## Exit Kodi&lt;br /&gt;
# Find your log file: [[Log_file/Advanced#Location|Wiki: Log File Location]]&lt;br /&gt;
# UPLOAD AN &#039;&#039;&#039;ENTIRE&#039;&#039;&#039; COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin]&lt;br /&gt;
# INCLUDE A LINK TO THE LOG IN YOUR POST ON THE FORUM&lt;br /&gt;
&lt;br /&gt;
Please do not turn on Kodi&#039;s debug mode before uploading a log unless asked to do so. This typically just generates more noise in the log, making it harder to pinpoint the problem.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Addon.xml&amp;diff=120219</id>
		<title>Addon.xml</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Addon.xml&amp;diff=120219"/>
		<updated>2016-04-12T10:41:39Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /*  element */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{mininav|[[Development]]|[[Add-on development]]}}&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Every skin, script, or plugin in Kodi contains an &amp;lt;code&amp;gt;addon.xml&amp;lt;/code&amp;gt; file which describes the add-on, providing credits, version information and dependencies. Below, we will explain how this file is structured and which elements must be used to create an add-on for Kodi. You can also consult the examples at the end to see how this file is laid out depending on if you are developing a skin or script.&lt;br /&gt;
&lt;br /&gt;
Every &amp;lt;code&amp;gt;addon.xml&amp;lt;/code&amp;gt; file has the same basic structure, this example is for a video plugin:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;yes&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;addon id=&amp;quot;plugin.addon.id&amp;quot; name=&amp;quot;Your Add-on&amp;quot; version=&amp;quot;1.2.3&amp;quot; provider-name=&amp;quot;You&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;requires&amp;gt;&lt;br /&gt;
    &amp;lt;import addon=&amp;quot;xbmc.python&amp;quot; version=&amp;quot;2.1.0&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;/requires&amp;gt;&lt;br /&gt;
  &amp;lt;extension point=&amp;quot;xbmc.python.pluginsource&amp;quot; library=&amp;quot;addon.py&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;provides&amp;gt;video&amp;lt;/provides&amp;gt;&lt;br /&gt;
  &amp;lt;/extension&amp;gt;&lt;br /&gt;
  &amp;lt;extension point=&amp;quot;xbmc.addon.metadata&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;summary lang=&amp;quot;en_gb&amp;quot;&amp;gt;Your add-on&#039;s summary&amp;lt;/summary&amp;gt;&lt;br /&gt;
    &amp;lt;description lang=&amp;quot;en_gb&amp;quot;&amp;gt;Your add-on&#039;s description&amp;lt;/description&amp;gt;&lt;br /&gt;
    &amp;lt;disclaimer lang=&amp;quot;en_gb&amp;quot;&amp;gt;&amp;lt;/disclaimer&amp;gt;&lt;br /&gt;
    &amp;lt;language&amp;gt;&amp;lt;/language&amp;gt;&lt;br /&gt;
    &amp;lt;platform&amp;gt;all&amp;lt;/platform&amp;gt;&lt;br /&gt;
    &amp;lt;license&amp;gt;&amp;lt;/license&amp;gt;&lt;br /&gt;
    &amp;lt;forum&amp;gt;&amp;lt;/forum&amp;gt;&lt;br /&gt;
    &amp;lt;website&amp;gt;&amp;lt;/website&amp;gt;&lt;br /&gt;
    &amp;lt;email&amp;gt;&amp;lt;/email&amp;gt;&lt;br /&gt;
    &amp;lt;source&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
  &amp;lt;/extension&amp;gt;&lt;br /&gt;
&amp;lt;/addon&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are a few important things to note in the above sample:&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;code&amp;gt;&amp;lt;addon&amp;gt;&amp;lt;/code&amp;gt; element must be present, and be the root node. It presents data about the add-on package as a whole.&lt;br /&gt;
* Inside the &amp;lt;code&amp;gt;&amp;lt;addon&amp;gt;&amp;lt;/code&amp;gt; element is a &amp;lt;code&amp;gt;&amp;lt;requires&amp;gt;&amp;lt;/code&amp;gt; element, listing all the dependencies that this add-on needs in order to function.&lt;br /&gt;
* Then there are one or more &amp;lt;code&amp;gt;&amp;lt;extension&amp;gt;&amp;lt;/code&amp;gt; elements, each of which describes a part of Kodi that the add-on extends.&lt;br /&gt;
* Finally, there is a specific &amp;lt;code&amp;gt;&amp;lt;extension&amp;gt;&amp;lt;/code&amp;gt; element that extends &amp;lt;code&amp;gt;&amp;quot;xbmc.addon.metadata&amp;quot;&amp;lt;/code&amp;gt;. This describes the add-on to the user.&lt;br /&gt;
&lt;br /&gt;
= Elements =&lt;br /&gt;
 &lt;br /&gt;
== &amp;lt;addon&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;&amp;lt;addon&amp;gt;&amp;lt;/code&amp;gt; element has 4 attributes, all required: &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;version&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;provider-name&amp;lt;/code&amp;gt;. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;addon id=&amp;quot;script.hello.world&amp;quot; name=&amp;quot;Hello World&amp;quot; version=&amp;quot;0.0.1&amp;quot; provider-name=&amp;quot;Dev1, Dev2&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== id attribute ===&lt;br /&gt;
&lt;br /&gt;
The id attribute is the unique identifier used for this add-on.  It must be unique, and must use only lowercase characters, periods, underscores, dashes and numbers.  This identifier is also used as the name of the folder that contains the add-on, so for ease of searching, we suggest you use something like &amp;lt;type&amp;gt;.&amp;lt;uniquename&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== version attribute ===&lt;br /&gt;
&lt;br /&gt;
The version attribute is used by Kodi to determine whether updates are available. This should be use a version scheme like &amp;lt;code&amp;gt;x.y.z&amp;lt;/code&amp;gt; (major.minor.patch). For example: &amp;lt;code&amp;gt;version=&amp;quot;0.0.1&amp;quot;&amp;lt;/code&amp;gt;. Generally, you&#039;ll start with a version of &amp;lt;code&amp;gt;0.y.z&amp;lt;/code&amp;gt; for test releases and once you feel it is ready for a full release, you&#039;d bump the version to &amp;lt;code&amp;gt;1.0.0&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== How versioning works ====&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;2.2.9&amp;lt;/code&amp;gt; is newer than &amp;lt;code&amp;gt;2.2.1&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;2.2.10&amp;lt;/code&amp;gt;   is newer than &amp;lt;code&amp;gt;2.2.1&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;2.3.0&amp;lt;/code&amp;gt;   is newer than &amp;lt;code&amp;gt;2.2.9&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;2.2.1&amp;lt;/code&amp;gt; is newer than &amp;lt;code&amp;gt;2.2.1~alpha&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;2.2.1&amp;lt;/code&amp;gt; is newer than &amp;lt;code&amp;gt;2.2.1~beta&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;2.2.1~beta&amp;lt;/code&amp;gt; is newer than &amp;lt;code&amp;gt;2.2.1~alpha&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;2.2.1~beta3&amp;lt;/code&amp;gt; is newer than &amp;lt;code&amp;gt;2.2.1~beta2&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;2.2.1~beta10&amp;lt;/code&amp;gt; is newer than &amp;lt;code&amp;gt;2.2.1~beta1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{tip|Text should only be added for a beta version. In other cases version number should only contain numbers.}}&lt;br /&gt;
&lt;br /&gt;
=== name attribute ===&lt;br /&gt;
&lt;br /&gt;
The name attribute is the name of the add-on as it appears in the UI.  This should be in English where it makes sense for it to be so, and is not translatable.&lt;br /&gt;
&lt;br /&gt;
=== provider-name attribute ===&lt;br /&gt;
&lt;br /&gt;
The provider-name attribute is used as the author field.  This could be a team of authors or a single author. If the add-on is maintained by multiple people please separate them with a comma (&amp;lt;code&amp;gt;,&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;requires&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;&amp;lt;requires&amp;gt;&amp;lt;/code&amp;gt; element contains one or more &amp;lt;code&amp;gt;&amp;lt;import&amp;gt;&amp;lt;/code&amp;gt; elements which specify which other add-ons this particular add-on requires, and which version of those add-ons it requires. These add-ons may be part of Kodi itself, or may be parts of other third-party add-ons.&lt;br /&gt;
&lt;br /&gt;
Kodi will only allow the add-on to be run if suitable versions of the (non-optional) add-ons on which this add-on depends are installed. When a user installs your add-on from an online repository via Kodi&#039;s add-on manager, Kodi attempts to resolve these dependencies, and install anything that your add-on relies on first. The dependency must be provided with the minimum version number your script/skin requires.&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
&lt;br /&gt;
Here is a sample &amp;lt;code&amp;gt;&amp;lt;requires&amp;gt;&amp;lt;/code&amp;gt; block that imports two required modules:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;requires&amp;gt;&lt;br /&gt;
  &amp;lt;import addon=&amp;quot;xbmc.python&amp;quot;                 version=&amp;quot;2.14.0&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;import addon=&amp;quot;script.module.elementtree&amp;quot;   version=&amp;quot;1.2.7&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;import addon=&amp;quot;script.module.simplejson&amp;quot;    version=&amp;quot;2.0.10&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/requires&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here&#039;s another example, which will only install on OpenELEC:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;requires&amp;gt;&lt;br /&gt;
  &amp;lt;import addon=&amp;quot;os.openelec.tv&amp;quot; version=&amp;quot;2.0&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/requires&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;import&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;code&amp;gt;&amp;lt;import&amp;gt;&amp;lt;/code&amp;gt; element describes one dependency for an add-on, with two required attributes: &amp;lt;code&amp;gt;addon&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;version&amp;lt;/code&amp;gt;. There is also an optional attribute called, fittingly, &amp;lt;code&amp;gt;optional&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If your add-on relies on other third-party add-ons, Kodi will automatically install them as well, provided they are available on an existing add-on repository. If they aren&#039;t available on any existing repository, the user must install the other add-ons themselves. Note that you need to include any Python libraries you need directly in your add-on; these can&#039;t be loaded with an &amp;lt;code&amp;gt;&amp;lt;import&amp;gt;&amp;lt;/code&amp;gt; element, since Kodi wouldn&#039;t know what to do with them.&lt;br /&gt;
&lt;br /&gt;
=== addon attribute ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;addon&amp;lt;/code&amp;gt; attribute specifies the id of the required add-on, e.g. &amp;lt;code&amp;gt;script.module.elementtree&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== version attribute ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;version&amp;lt;/code&amp;gt; attribute specifies the minimum version of the required add-on to be installed.&lt;br /&gt;
&lt;br /&gt;
==== Dependency versions ====&lt;br /&gt;
&lt;br /&gt;
Each different Kodi version might require you to use a higher version of the &amp;lt;code&amp;gt;xbmc.*&amp;lt;/code&amp;gt; add-on dependencies to control on which version of Kodi the add-on can be installed.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;prettytable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|+ Current versions&lt;br /&gt;
! Kodi version !! xbmc.python !! xbmc.gui !! xbmc.json !! xbmc.metadata !! xbmc.addon&lt;br /&gt;
|-&lt;br /&gt;
| Dharma 10.1 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;Deprecated&amp;lt;/font&amp;gt;|| 1.0 || 2.11 || 2.0|| 1.0 || 0.1&lt;br /&gt;
|-&lt;br /&gt;
| Eden 11.0 &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;Deprecated&amp;lt;/font&amp;gt; || 2.0 || 3.0 || 4.0 || 1.0 || 11.0&lt;br /&gt;
|-&lt;br /&gt;
| Frodo 12.x &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;Deprecated&amp;lt;/font&amp;gt;|| 2.1.0 || 4.0.0 || 6.0.0 || 2.1.0 || 12.0.0&lt;br /&gt;
|-&lt;br /&gt;
| Gotham 13.x || 2.14.0 (ABI 2.1.0) || 5.0.1 || 6.6.0 (ABI 6.0.0) || 2.1.0 || 13.0.0 (ABI 12.0.0)&lt;br /&gt;
|-&lt;br /&gt;
| Helix 14.x || 2.19.0 (ABI 2.1.0) || 5.3.0 || 6.20.0 (ABI 6.0.0) || 2.1.0 || 14.0.0 (ABI 12.0.0)&lt;br /&gt;
|-&lt;br /&gt;
| Isengard 15.x || 2.20.0 (ABI 2.1.0) || 5.9.0 (ABI 5.3.0) || 6.25.1 (ABI 6.0.0) || 2.1.0 || 15.0.0 (ABI 12.0.0)&lt;br /&gt;
|-&lt;br /&gt;
| Jarvis 16.x || 2.24.0 (ABI 2.1.0) || 5.10.0 || 6.32.4 (ABI 6.0.0) || 2.1.0 || 16.0.0 (ABI 12.0.0)&lt;br /&gt;
|-&lt;br /&gt;
| Krypton 17.x || 2.25.0 (ABI 2.1.0) || 5.11.0 || 6.32.4 (ABI 6.0.0) || 2.1.0 || 17.0.0 (ABI 12.0.0)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Each Kodi version contain a certain backwards compatibility. For example add-ons made for Gotham 13.x can still work ion Jarvis 16.x. Do note that this might change in the future. The &#039;&#039;&#039;ABI&#039;&#039;&#039; version you see in the table above is the backwards compatibility version for which add-ons are still marked &amp;quot;working&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== optional attribute ===&lt;br /&gt;
&lt;br /&gt;
The dependency may be made optional by setting the &amp;lt;code&amp;gt;optional&amp;lt;/code&amp;gt; attribute to &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;. This will only install the dependency when the add-on actually needs it. Even if this dependency is missing, the add-on can still be installed.&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;extension&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;&amp;lt;extension&amp;gt;&amp;lt;/code&amp;gt; element describes the technical aspects of this add-on. It will have at least a point attribute which will give the part of Kodi that the add-on extends. For instance, the &amp;lt;code&amp;gt;addon.xml&amp;lt;/code&amp;gt; file for the Confluence skin extends the &amp;lt;code&amp;gt;xbmc.gui.skin&amp;lt;/code&amp;gt; part of xbmc. All available extension points are given below.&lt;br /&gt;
&lt;br /&gt;
The various extension points that Kodi provides are given in the list below.&lt;br /&gt;
{| class=&amp;quot;prettytable&amp;quot;&lt;br /&gt;
!Extension point&lt;br /&gt;
!Add-on Category&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;[[Skinning|xbmc.gui.skin]]&amp;lt;/code&amp;gt;&lt;br /&gt;
|Skin&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;xbmc.webinterface&amp;lt;/code&amp;gt;&lt;br /&gt;
|Web interface&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;[[Add-on repositories|xbmc.addon.repository]]&amp;lt;/code&amp;gt;&lt;br /&gt;
|&#039;&#039;None&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;[[HOW-TO:_Automatically_start_addons_using_services|xbmc.service]]&amp;lt;/code&amp;gt;&lt;br /&gt;
|Services&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;xbmc.metadata.scraper.albums&amp;lt;/code&amp;gt;&lt;br /&gt;
|Album information&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;xbmc.metadata.scraper.artists&amp;lt;/code&amp;gt;&lt;br /&gt;
|Artist information&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;xbmc.metadata.scraper.movies&amp;lt;/code&amp;gt;&lt;br /&gt;
|Movie information&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;xbmc.metadata.scraper.musicvideos&amp;lt;/code&amp;gt;&lt;br /&gt;
|Music video information&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;xbmc.metadata.scraper.tvshows&amp;lt;/code&amp;gt;&lt;br /&gt;
|TV information&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;xbmc.metadata.scraper.library&amp;lt;/code&amp;gt;&lt;br /&gt;
|&#039;&#039;None&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;xbmc.ui.screensaver&amp;lt;/code&amp;gt;&lt;br /&gt;
|Screensaver&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;xbmc.player.musicviz&amp;lt;/code&amp;gt;&lt;br /&gt;
|Visualization&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;[[Plugin sources#What Kodi requires for your add-on|xbmc.python.pluginsource]]&amp;lt;/code&amp;gt;&lt;br /&gt;
|Music Add-ons (audio) / Picture Add-ons (image) / Program Add-ons (executable) / Video Add-ons (video)&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;[[Script sources#What Kodi requires for your add-on|xbmc.python.script]]&amp;lt;/code&amp;gt;&lt;br /&gt;
|Music Add-ons (audio) / Picture Add-ons (image) / Program Add-ons (executable) / Video Add-ons (video)&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;xbmc.python.weather&amp;lt;/code&amp;gt;&lt;br /&gt;
|Weather&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;xbmc.subtitle.module&amp;lt;/code&amp;gt;&lt;br /&gt;
|Subtitle service module&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;[[Script lyrics#What Kodi requires for your add-on|xbmc.python.lyrics]]&amp;lt;/code&amp;gt;&lt;br /&gt;
|Lyrics&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;[[Script library#What Kodi requires for your add-on|xbmc.python.library]]&amp;lt;/code&amp;gt;&lt;br /&gt;
|&#039;&#039;None&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;xbmc.python.module&amp;lt;/code&amp;gt;&lt;br /&gt;
|These don&#039;t show up in the addon browser and are purely as support for other scripts.&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;xbmc.addon.video&amp;lt;/code&amp;gt;&lt;br /&gt;
|Video Add-ons (video)&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;xbmc.addon.audio&amp;lt;/code&amp;gt;&lt;br /&gt;
|Music Add-ons (audio)&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;xbmc.addon.image&amp;lt;/code&amp;gt;&lt;br /&gt;
|Picture Add-ons (image)&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;kodi.resource.images&amp;lt;/code&amp;gt;&lt;br /&gt;
|Additional image files&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;kodi.resource.language&amp;lt;/code&amp;gt;&lt;br /&gt;
|Additional language files&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Add-ons that don&#039;t correspond to a specific add-on category can not be installed by users. These are usually supporting or shared add-ons that are installed automatically by the add-ons that require them.&lt;br /&gt;
&lt;br /&gt;
=== xbmc.python.pluginsource ===&lt;br /&gt;
{{See also|Plugin sources}}&lt;br /&gt;
&lt;br /&gt;
The most common extension point that will be used by plugin addon developers is &amp;lt;code&amp;gt;xbmc.python.pluginsource&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== library attribute ====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;&amp;lt;extension point=&amp;quot;xbmc.python.pluginsource&amp;quot;&amp;gt;&amp;lt;/code&amp;gt; element has an extra attribute: &amp;lt;code&amp;gt;library&amp;lt;/code&amp;gt;. This is the name of the Python script (startup script) that will be run when the add-on is activated. This file must exist in the root of your add-on directory.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;provides&amp;gt; element ====&lt;br /&gt;
&lt;br /&gt;
The extension has an additional child element named &amp;lt;code&amp;gt;&amp;lt;provides&amp;gt;&amp;lt;/code&amp;gt;, which contains a whitespace separated list of &amp;lt;code&amp;gt;image&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;video&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;audio&amp;lt;/code&amp;gt;, and/or &amp;lt;code&amp;gt;executable&amp;lt;/code&amp;gt;. This determines in what area (or context) of the Kodi system your addon will make itself visible in (please note that this applies only to plugin extension points):&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;prettytable&amp;quot;&lt;br /&gt;
!Provides&lt;br /&gt;
!Appears in&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;image&amp;lt;/code&amp;gt;&lt;br /&gt;
|Pictures&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;audio&amp;lt;/code&amp;gt;&lt;br /&gt;
|Music&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;video&amp;lt;/code&amp;gt;&lt;br /&gt;
|Video&lt;br /&gt;
|-&lt;br /&gt;
|&amp;lt;code&amp;gt;executable&amp;lt;/code&amp;gt;&lt;br /&gt;
|Programs&lt;br /&gt;
|-&lt;br /&gt;
|&#039;&#039;(blank)&#039;&#039;&lt;br /&gt;
|Not visible&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;extension point=&amp;quot;xbmc.python.pluginsource&amp;quot; library=&amp;quot;gpodderxbmc.py&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;provides&amp;gt;audio video&amp;lt;/provides&amp;gt;&lt;br /&gt;
&amp;lt;/extension&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== xbmc.addon.metadata ===&lt;br /&gt;
&lt;br /&gt;
This special extension point &#039;&#039;must&#039;&#039; be provided by all add-ons, and is the way that your add-on is described to users of the Kodi add-on manager.&lt;br /&gt;
&lt;br /&gt;
==== Required elements ====&lt;br /&gt;
&lt;br /&gt;
There are several elements that this should contain and all are compulsory (except the broken tag). Each of the elements below must always be present in English as a minimum.&lt;br /&gt;
&lt;br /&gt;
Many of these elements can be translated into multiple languages and should be added once for each supported language. See the [[List of language codes (ISO-639:1988)]] for possible language strings. If there&#039;s no &amp;lt;code&amp;gt;lang&amp;lt;/code&amp;gt; attribute for a translatable element, it defaults to English. However, even for English, adding the &amp;lt;code&amp;gt;lang&amp;lt;/code&amp;gt; attribute is recommended.&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;summary&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
One or more &amp;lt;code&amp;gt;&amp;lt;summary&amp;gt;&amp;lt;/code&amp;gt; elements provide a short summary of what the add-on does. This should be a single sentence. It may be translated into multiple languages.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;summary lang=&amp;quot;en&amp;quot;&amp;gt;Hello World script provides some basic examples on how to create your first script.&amp;lt;/summary&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From Kodi v15 Isengard we recommend you use&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;summary lang=&amp;quot;en_GB&amp;quot;&amp;gt;Hello World script provides some basic examples on how to create your first script.&amp;lt;/summary&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;description&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
One or more &amp;lt;code&amp;gt;&amp;lt;description&amp;gt;&amp;lt;/code&amp;gt; elements provide a more detailed summary of what the add-on does. It may be translated into multiple languages.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;description lang=&amp;quot;en&amp;quot;&amp;gt;Hello World script provides some basic examples on how to create your first script&lt;br /&gt;
 and hopefully will increase the number of Kodi users to start creating their own addons.&amp;lt;/description&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From Kodi v15 Isengard we recommend you use&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;description lang=&amp;quot;en_GB&amp;quot;&amp;gt;Hello World script provides some basic examples on how to create your first script&lt;br /&gt;
 and hopefully will increase the number of Kodi users to start creating their own addons.&amp;lt;/description&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;disclaimer&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
One or more &amp;lt;code&amp;gt;&amp;lt;disclaimer&amp;gt;&amp;lt;/code&amp;gt; elements that indicate what (if any) things the user should know about the add-on. There is no need to have a disclaimer if you don&#039;t want one, though if something requires settings, or only works in a particular country then you may want to state this here. It may be translated into multiple languages.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;disclaimer lang=&amp;quot;en&amp;quot;&amp;gt;Feel free to use this script. For information visit the wiki.&amp;lt;/disclaimer&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
From Kodi v15 Isengard we recommend you use&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;disclaimer lang=&amp;quot;en_GB&amp;quot;&amp;gt;Feel free to use this script. For information visit the wiki.&amp;lt;/disclaimer&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;platform&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;&amp;lt;platform&amp;gt;&amp;lt;/code&amp;gt; tag specifies which platforms (operating systems, hardware) this add-on runs on. Many add-ons will run on all platforms, so &amp;lt;code&amp;gt;all&amp;lt;/code&amp;gt; is an option. If the platform tag is missing, we assume the add-on runs on all platforms. A combination of these is also possible. Currently available options are:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;all&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;linux&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;osx&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;osx64&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;osx32&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;ios&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;windx&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;android&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;platform&amp;gt;all&amp;lt;/platform&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;language&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;&amp;lt;language&amp;gt;&amp;lt;/code&amp;gt; elements indicate the language(s) of the &#039;&#039;content&#039;&#039; provided by your add-on. It applies to plugins, scripts, scrapers etc. This allows browsing the add-on list by language. When there is no specific language provided in your content, leave it blank.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;language&amp;gt;en de fr&amp;lt;/language&amp;gt;&lt;br /&gt;
    or&lt;br /&gt;
&amp;lt;language&amp;gt;&amp;lt;/language&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;license&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;&amp;lt;license&amp;gt;&amp;lt;/code&amp;gt; element indicates what license is used for this add-on.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;license&amp;gt;GNU GENERAL PUBLIC LICENSE. Version 2, June 1991&amp;lt;/license&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;forum&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;&amp;lt;forum&amp;gt;&amp;lt;/code&amp;gt; element provides the forum thread URL for this specific add-on. Leave this blank if there is no forum thread.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;forum&amp;gt;http://www.myaddonwebsite.com/forum.php?thread=12345&amp;lt;/forum&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;website&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;&amp;lt;website&amp;gt;&amp;lt;/code&amp;gt; element provides the website URL for this specific add-on.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;website&amp;gt;http://www.myaddonwebsite.com/&amp;lt;/website&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;nowiki&amp;gt;&amp;lt;source&amp;gt;&amp;lt;/nowiki&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;source&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; element provides the URL for the source code for this specific add-on.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;source&amp;gt;http://github.com/someone/myaddon&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;email&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;&amp;lt;email&amp;gt;&amp;lt;/code&amp;gt; element provides the email address of the author if he wishes to do so for this specific add-on. Here are two examples of how you can make it look (the second one it harder for spambots to use). This can be left blank if you do not want to make your email address public.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;email&amp;gt;foo@bar.com&amp;lt;/email&amp;gt;&lt;br /&gt;
    or&lt;br /&gt;
&amp;lt;email&amp;gt;foo at bar dot com&amp;lt;/email&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===== &amp;lt;broken&amp;gt; =====&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;&amp;lt;broken&amp;gt;&amp;lt;/code&amp;gt; tag will mark the add-on as broken in the Kodi repo and provide the reason why. You don&#039;t need to do a version bump for this to work. However a bump is recommended as you could also add this to the changelog.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;broken&amp;gt;deprecated&amp;lt;/broken&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Skin specific elements ==&lt;br /&gt;
=== Overview ===&lt;br /&gt;
{| class=&amp;quot;prettytable&amp;quot;&lt;br /&gt;
|  &#039;&#039;&#039;effectslowdown&#039;&#039;&#039;&lt;br /&gt;
|  A multiplier that is applied to all &amp;lt;animation&amp;gt; effect lengths in the skin. Useful to slow down all animations globally so that you can better configure timings and see interactions between animating controls.&lt;br /&gt;
|- &lt;br /&gt;
|  &#039;&#039;&#039;debugging&#039;&#039;&#039;&lt;br /&gt;
|  When set to true, it&#039;ll display onscreen debug information (xml filename, mouse position and focused control type and name) in the skin.&lt;br /&gt;
|- &lt;br /&gt;
|  &#039;&#039;&#039;res&#039;&#039;&#039;&lt;br /&gt;
|  Support for arbitrary skin resolutions.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== How window xml files are found ===&lt;br /&gt;
&lt;br /&gt;
Kodi can run in many differing resolutions, and a skin should try and cater to all these resolutions. The easiest way is to develop for one specific resolution and make sure that all controls contain &amp;lt;width&amp;gt; and &amp;lt;height&amp;gt; tags. That way, Kodi can scale the controls to the new screen resolution.&lt;br /&gt;
&lt;br /&gt;
However, you may choose to develop alternative window xml files for differing resolutions (such as for HDTV resolutions, or for widescreen versus 4x3 resolutions).&lt;br /&gt;
&lt;br /&gt;
The order that Kodi looks for it&#039;s skin files are as follows:&lt;br /&gt;
&lt;br /&gt;
# It first looks in the current screenmode folder (one of 1080i, 720p, NTSC16x9, NTSC, PAL16x9 or PAL)&lt;br /&gt;
# If the current screenmode is 1080i and there&#039;s no 1080i folder, it then looks in the 720p folder.&lt;br /&gt;
# Finally, it looks in the &#039;&#039;&#039;res&#039;&#039;&#039; folder.&lt;br /&gt;
&lt;br /&gt;
This allows you to just put any window files that do not require special treatment for 16x9 resolutions etc. in the &amp;lt;defaultresolution&amp;gt; folder, preventing needless repetition.&lt;br /&gt;
&lt;br /&gt;
= Examples =&lt;br /&gt;
&lt;br /&gt;
== addon.xml for skins ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
﻿&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;addon&lt;br /&gt;
  id=&amp;quot;skin.confluence&amp;quot;&lt;br /&gt;
  version=&amp;quot;2.1.3&amp;quot;&lt;br /&gt;
  name=&amp;quot;Confluence&amp;quot;&lt;br /&gt;
  provider-name=&amp;quot;Jezz_X, Team Kodi&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;requires&amp;gt;&lt;br /&gt;
    &amp;lt;import addon=&amp;quot;xbmc.gui&amp;quot; version=&amp;quot;4.0.0&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;/requires&amp;gt;&lt;br /&gt;
  &amp;lt;extension&lt;br /&gt;
    point=&amp;quot;xbmc.gui.skin&amp;quot;&lt;br /&gt;
    debugging=&amp;quot;false&amp;quot;&lt;br /&gt;
    effectslowdown=&amp;quot;0.75&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;res width=&amp;quot;1280&amp;quot; height=&amp;quot;720&amp;quot; aspect=&amp;quot;16:9&amp;quot; default=&amp;quot;true&amp;quot; folder=&amp;quot;720p&amp;quot; /&amp;gt;&lt;br /&gt;
  &amp;lt;/extension&amp;gt;&lt;br /&gt;
  &amp;lt;extension point=&amp;quot;xbmc.addon.metadata&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;summary lang=&amp;quot;en&amp;quot;&amp;gt;Confluence skin by Jezz_X. (Kodi&#039;s default skin)&amp;lt;/summary&amp;gt;&lt;br /&gt;
    &amp;lt;description lang=&amp;quot;en&amp;quot;&amp;gt;Confluence is the default skin for Kodi 9.11 and above. It is a combination of concepts from many popular skins, and attempts to embrace and integrate their good ideas into a skin that should be easy for first time Kodi users to understand and use.&amp;lt;/description&amp;gt;&lt;br /&gt;
    &amp;lt;disclaimer lang=&amp;quot;en&amp;quot;&amp;gt;Confluence is the default skin for Kodi, removing it may cause issues&amp;lt;/disclaimer&amp;gt;&lt;br /&gt;
    &amp;lt;platform&amp;gt;all&amp;lt;/platform&amp;gt;&lt;br /&gt;
    &amp;lt;license&amp;gt;GNU GENERAL PUBLIC LICENSE. Version 2, June 1991&amp;lt;/license&amp;gt;&lt;br /&gt;
    &amp;lt;forum&amp;gt;&amp;lt;/forum&amp;gt;&lt;br /&gt;
    &amp;lt;website&amp;gt;&amp;lt;/website&amp;gt;&lt;br /&gt;
    &amp;lt;email&amp;gt;&amp;lt;/email&amp;gt;&lt;br /&gt;
    &amp;lt;source&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
  &amp;lt;/extension&amp;gt;&lt;br /&gt;
&amp;lt;/addon&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
One thing to note is that &amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;all tag names are lower case.&amp;lt;/font&amp;gt; XML tag names are case sensitive!&lt;br /&gt;
&lt;br /&gt;
== addon.xml for scripts ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;yes&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;addon&lt;br /&gt;
    id=&amp;quot;script.artwork.downloader&amp;quot;&lt;br /&gt;
    name=&amp;quot;Artwork Downloader&amp;quot;&lt;br /&gt;
    version=&amp;quot;12.0.12&amp;quot;&lt;br /&gt;
    provider-name=&amp;quot;Martijn&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;requires&amp;gt;&lt;br /&gt;
    &amp;lt;import addon=&amp;quot;xbmc.python&amp;quot;                 version=&amp;quot;2.1.0&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;import addon=&amp;quot;xbmc.json&amp;quot;                   version=&amp;quot;6.0.0&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;import addon=&amp;quot;xbmc.addon&amp;quot;                  version=&amp;quot;12.0.0&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;import addon=&amp;quot;script.module.elementtree&amp;quot;   version=&amp;quot;1.2.7&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;import addon=&amp;quot;script.module.simplejson&amp;quot;    version=&amp;quot;2.0.10&amp;quot; optional=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;import addon=&amp;quot;script.common.plugin.cache&amp;quot;  version=&amp;quot;1.3.0&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;/requires&amp;gt;&lt;br /&gt;
  &amp;lt;extension point=&amp;quot;xbmc.python.script&amp;quot;         library=&amp;quot;default.py&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;provides&amp;gt;executable&amp;lt;/provides&amp;gt;&lt;br /&gt;
  &amp;lt;/extension&amp;gt;&lt;br /&gt;
  &amp;lt;extension point=&amp;quot;xbmc.service&amp;quot; library=&amp;quot;service.py&amp;quot; start=&amp;quot;login&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;extension point=&amp;quot;xbmc.addon.metadata&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;summary lang=&amp;quot;en&amp;quot;&amp;gt;Downloads Artwork for TV shows, Movies and Musicvideos in your library&amp;lt;/summary&amp;gt;&lt;br /&gt;
    &amp;lt;description lang=&amp;quot;en&amp;quot;&amp;gt;Downloads all available artwork for TV shows, Movies and Musicvideos in your library. Check the options for supported artwork[CR]Artwork sources:[CR]www.fanart.tv[CR]www.thetvdb.com[CR]www.themoviedb.org[CR]Remark:[CR]Check your skin to see what type of artwork is supported![CR]Each TV Show/Movie must have its own folder![CR]Skin integration:[CR]See readme file&amp;lt;/description&amp;gt;&lt;br /&gt;
    &amp;lt;disclaimer lang=&amp;quot;en&amp;quot;&amp;gt;For bugs, requests or general questions visit the Artwork Downloader thread on the Kodi forum.&amp;lt;/disclaimer&amp;gt;&lt;br /&gt;
    &amp;lt;language&amp;gt;&amp;lt;/language&amp;gt;&lt;br /&gt;
    &amp;lt;platform&amp;gt;all&amp;lt;/platform&amp;gt;&lt;br /&gt;
    &amp;lt;license&amp;gt;GNU GENERAL PUBLIC LICENSE. Version 2, June 1991&amp;lt;/license&amp;gt;&lt;br /&gt;
    &amp;lt;forum&amp;gt;&amp;lt;/forum&amp;gt;&lt;br /&gt;
    &amp;lt;website&amp;gt;&amp;lt;/website&amp;gt;&lt;br /&gt;
    &amp;lt;email&amp;gt;&amp;lt;/email&amp;gt;&lt;br /&gt;
    &amp;lt;source&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
  &amp;lt;/extension&amp;gt;&lt;br /&gt;
&amp;lt;/addon&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Schema Definition =&lt;br /&gt;
&lt;br /&gt;
The XML schema definition for &amp;lt;code&amp;gt;addon.xml&amp;lt;/code&amp;gt; is located [https://github.com/xbmc/xbmc/blob/master/addons/xbmc.addon/metadata.xsd here].&lt;br /&gt;
&lt;br /&gt;
{{frodo updated}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-on development]]&lt;br /&gt;
[[Category:Skin development]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=120074</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=120074"/>
		<updated>2016-04-04T11:50:07Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Argument variable substitution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python, script or json-rpc-notify.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http:&lt;br /&gt;
*# Put only the url with port here. Further specification will be done on the events page when invoking this task.&lt;br /&gt;
*# Optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
*# Choose which http request type is desired (most commonly GET or POST).&lt;br /&gt;
*# For POST or PUT, choose what Content-Type you want in the header.&lt;br /&gt;
*# Other CGI query type data (i.e ?var1=x&amp;amp;var2=y) will be done on the events page.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications. This is a json notification receiver event. It is completely separate from the json-rpc-notify TASK which sends notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
*A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
*The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
*Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
*To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
*Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
*If you need to ensure that a space is not split, for a space use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
*Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
*   -Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
*When the task that is being run is an http task using either POST or PUT, anything following double question-mark &amp;quot;??&amp;quot; will be treated as payload.&lt;br /&gt;
*# The ?? will not appear as part of the transmitted url string.&lt;br /&gt;
*# What you put following the ?? should depend on the Content-Type selected for the task on the Tasks settings page.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
If you have the [http://addons.kodi.tv/show/script.xbmc.debug.log/ Kodi log uploader addon] installed, then you will see a clickable link to send your log directly from this page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to provide information via a settings page to configure it properly.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If things broke after a new update, please try rebuilding your settings first:&lt;br /&gt;
# Note down your settings&lt;br /&gt;
# On the settings page click &#039;Default&#039; and then click &#039;OK&#039;&lt;br /&gt;
# Rebuid your settings&lt;br /&gt;
# Click OK&lt;br /&gt;
# Restart Kodi&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected after trying the above,&lt;br /&gt;
# From the &#039;General&#039; Settings page:&lt;br /&gt;
## Turn on &#039;Show debugging info in normal log&#039;&lt;br /&gt;
## Click OK&lt;br /&gt;
## Recreate your problem&lt;br /&gt;
## Go back to Settings and on the General page, click to write your settings into the log.&lt;br /&gt;
## Exit Kodi&lt;br /&gt;
# Find your log file: [[Log_file/Advanced#Location|Wiki: Log File Location]]&lt;br /&gt;
# UPLOAD AN &#039;&#039;&#039;ENTIRE&#039;&#039;&#039; COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin]&lt;br /&gt;
# INCLUDE A LINK TO THE LOG IN YOUR POST ON THE FORUM&lt;br /&gt;
&lt;br /&gt;
Please do not turn on Kodi&#039;s debug mode before uploading a log unless asked to do so. This typically just generates more noise in the log, making it harder to pinpoint the problem.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=120073</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=120073"/>
		<updated>2016-04-04T11:49:44Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Argument variable substitution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python, script or json-rpc-notify.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http:&lt;br /&gt;
*# Put only the url with port here. Further specification will be done on the events page when invoking this task.&lt;br /&gt;
*# Optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
*# Choose which http request type is desired (most commonly GET or POST).&lt;br /&gt;
*# For POST or PUT, choose what Content-Type you want in the header.&lt;br /&gt;
*# Other CGI query type data (i.e ?var1=x&amp;amp;var2=y) will be done on the events page.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications. This is a json notification receiver event. It is completely separate from the json-rpc-notify TASK which sends notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
*A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
*The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
*Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
*To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
*Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
*If you need to ensure that a space is not split, for a space use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
*Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
**Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
*When the task that is being run is an http task using either POST or PUT, anything following double question-mark &amp;quot;??&amp;quot; will be treated as payload.&lt;br /&gt;
*# The ?? will not appear as part of the transmitted url string.&lt;br /&gt;
*# What you put following the ?? should depend on the Content-Type selected for the task on the Tasks settings page.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
If you have the [http://addons.kodi.tv/show/script.xbmc.debug.log/ Kodi log uploader addon] installed, then you will see a clickable link to send your log directly from this page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to provide information via a settings page to configure it properly.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If things broke after a new update, please try rebuilding your settings first:&lt;br /&gt;
# Note down your settings&lt;br /&gt;
# On the settings page click &#039;Default&#039; and then click &#039;OK&#039;&lt;br /&gt;
# Rebuid your settings&lt;br /&gt;
# Click OK&lt;br /&gt;
# Restart Kodi&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected after trying the above,&lt;br /&gt;
# From the &#039;General&#039; Settings page:&lt;br /&gt;
## Turn on &#039;Show debugging info in normal log&#039;&lt;br /&gt;
## Click OK&lt;br /&gt;
## Recreate your problem&lt;br /&gt;
## Go back to Settings and on the General page, click to write your settings into the log.&lt;br /&gt;
## Exit Kodi&lt;br /&gt;
# Find your log file: [[Log_file/Advanced#Location|Wiki: Log File Location]]&lt;br /&gt;
# UPLOAD AN &#039;&#039;&#039;ENTIRE&#039;&#039;&#039; COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin]&lt;br /&gt;
# INCLUDE A LINK TO THE LOG IN YOUR POST ON THE FORUM&lt;br /&gt;
&lt;br /&gt;
Please do not turn on Kodi&#039;s debug mode before uploading a log unless asked to do so. This typically just generates more noise in the log, making it harder to pinpoint the problem.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=120072</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=120072"/>
		<updated>2016-04-04T11:45:21Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Create your own custom task */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python, script or json-rpc-notify.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http:&lt;br /&gt;
*# Put only the url with port here. Further specification will be done on the events page when invoking this task.&lt;br /&gt;
*# Optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
*# Choose which http request type is desired (most commonly GET or POST).&lt;br /&gt;
*# For POST or PUT, choose what Content-Type you want in the header.&lt;br /&gt;
*# Other CGI query type data (i.e ?var1=x&amp;amp;var2=y) will be done on the events page.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications. This is a json notification receiver event. It is completely separate from the json-rpc-notify TASK which sends notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
*A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
*The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
*Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
*To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
*Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
*If you need to ensure that a space is not split, use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
*Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
*Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
*When the task that is being run is an http task using either POST or PUT, anything following double question-mark &amp;quot;??&amp;quot; will be treated as payload.&lt;br /&gt;
*# The ?? will not appear as part of the transmitted url string.&lt;br /&gt;
*# What you put following the ?? should depend on the Content-Type selected for the task on the Tasks settings page.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
If you have the [http://addons.kodi.tv/show/script.xbmc.debug.log/ Kodi log uploader addon] installed, then you will see a clickable link to send your log directly from this page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to provide information via a settings page to configure it properly.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If things broke after a new update, please try rebuilding your settings first:&lt;br /&gt;
# Note down your settings&lt;br /&gt;
# On the settings page click &#039;Default&#039; and then click &#039;OK&#039;&lt;br /&gt;
# Rebuid your settings&lt;br /&gt;
# Click OK&lt;br /&gt;
# Restart Kodi&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected after trying the above,&lt;br /&gt;
# From the &#039;General&#039; Settings page:&lt;br /&gt;
## Turn on &#039;Show debugging info in normal log&#039;&lt;br /&gt;
## Click OK&lt;br /&gt;
## Recreate your problem&lt;br /&gt;
## Go back to Settings and on the General page, click to write your settings into the log.&lt;br /&gt;
## Exit Kodi&lt;br /&gt;
# Find your log file: [[Log_file/Advanced#Location|Wiki: Log File Location]]&lt;br /&gt;
# UPLOAD AN &#039;&#039;&#039;ENTIRE&#039;&#039;&#039; COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin]&lt;br /&gt;
# INCLUDE A LINK TO THE LOG IN YOUR POST ON THE FORUM&lt;br /&gt;
&lt;br /&gt;
Please do not turn on Kodi&#039;s debug mode before uploading a log unless asked to do so. This typically just generates more noise in the log, making it harder to pinpoint the problem.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=120071</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=120071"/>
		<updated>2016-04-04T11:44:00Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Argument variable substitution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python, script or json-rpc-notify.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http:&lt;br /&gt;
*# Put only the url with port here. Further specification will be done on the events page when invoking this task.&lt;br /&gt;
*# Optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
*# Choose which http request type is desired (most commonly GET or POST).&lt;br /&gt;
*# For POST or PUT, choose what Content-Type you want in the header.&lt;br /&gt;
*# Other CGI query type data (i.e ?var1=x&amp;amp;var2=y) will be done on the events page.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications. This is a json notification receiver event. It is completely separate from the json-rpc-notify TASK which sends notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
*A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
*The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
*Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
*To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
*Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
*If you need to ensure that a space is not split, use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
*Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
*Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
*When the task that is being run is an http task using either POST or PUT, anything following double question-mark &amp;quot;??&amp;quot; will be treated as payload.&lt;br /&gt;
*# The ?? will not appear as part of the transmitted url string.&lt;br /&gt;
*# What you put following the ?? should depend on the Content-Type selected for the task on the Tasks settings page.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
If you have the [http://addons.kodi.tv/show/script.xbmc.debug.log/ Kodi log uploader addon] installed, then you will see a clickable link to send your log directly from this page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to give it information via the settings page.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If things broke after a new update, please try rebuilding your settings first:&lt;br /&gt;
# Note down your settings&lt;br /&gt;
# On the settings page click &#039;Default&#039; and then click &#039;OK&#039;&lt;br /&gt;
# Rebuid your settings&lt;br /&gt;
# Click OK&lt;br /&gt;
# Restart Kodi&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected after trying the above,&lt;br /&gt;
# From the &#039;General&#039; Settings page:&lt;br /&gt;
## Turn on &#039;Show debugging info in normal log&#039;&lt;br /&gt;
## Click OK&lt;br /&gt;
## Recreate your problem&lt;br /&gt;
## Go back to Settings and on the General page, click to write your settings into the log.&lt;br /&gt;
## Exit Kodi&lt;br /&gt;
# Find your log file: [[Log_file/Advanced#Location|Wiki: Log File Location]]&lt;br /&gt;
# UPLOAD AN &#039;&#039;&#039;ENTIRE&#039;&#039;&#039; COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin]&lt;br /&gt;
# INCLUDE A LINK TO THE LOG IN YOUR POST ON THE FORUM&lt;br /&gt;
&lt;br /&gt;
Please do not turn on Kodi&#039;s debug mode before uploading a log unless asked to do so. This typically just generates more noise in the log, making it harder to pinpoint the problem.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=120070</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=120070"/>
		<updated>2016-04-04T11:38:42Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Settings - Tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python, script or json-rpc-notify.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http:&lt;br /&gt;
*# Put only the url with port here. Further specification will be done on the events page when invoking this task.&lt;br /&gt;
*# Optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
*# Choose which http request type is desired (most commonly GET or POST).&lt;br /&gt;
*# For POST or PUT, choose what Content-Type you want in the header.&lt;br /&gt;
*# Other CGI query type data (i.e ?var1=x&amp;amp;var2=y) will be done on the events page.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications. This is a json notification receiver event. It is completely separate from the json-rpc-notify TASK which sends notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
If you need to ensure that a space is not split, use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
If you have the [http://addons.kodi.tv/show/script.xbmc.debug.log/ Kodi log uploader addon] installed, then you will see a clickable link to send your log directly from this page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to give it information via the settings page.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If things broke after a new update, please try rebuilding your settings first:&lt;br /&gt;
# Note down your settings&lt;br /&gt;
# On the settings page click &#039;Default&#039; and then click &#039;OK&#039;&lt;br /&gt;
# Rebuid your settings&lt;br /&gt;
# Click OK&lt;br /&gt;
# Restart Kodi&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected after trying the above,&lt;br /&gt;
# From the &#039;General&#039; Settings page:&lt;br /&gt;
## Turn on &#039;Show debugging info in normal log&#039;&lt;br /&gt;
## Click OK&lt;br /&gt;
## Recreate your problem&lt;br /&gt;
## Go back to Settings and on the General page, click to write your settings into the log.&lt;br /&gt;
## Exit Kodi&lt;br /&gt;
# Find your log file: [[Log_file/Advanced#Location|Wiki: Log File Location]]&lt;br /&gt;
# UPLOAD AN &#039;&#039;&#039;ENTIRE&#039;&#039;&#039; COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin]&lt;br /&gt;
# INCLUDE A LINK TO THE LOG IN YOUR POST ON THE FORUM&lt;br /&gt;
&lt;br /&gt;
Please do not turn on Kodi&#039;s debug mode before uploading a log unless asked to do so. This typically just generates more noise in the log, making it harder to pinpoint the problem.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=120029</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=120029"/>
		<updated>2016-03-27T13:58:31Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* FAQs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python, script or json-rpc-notify.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications. This is a json notification receiver event. It is completely separate from the json-rpc-notify TASK which sends notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
If you need to ensure that a space is not split, use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
If you have the [http://addons.kodi.tv/show/script.xbmc.debug.log/ Kodi log uploader addon] installed, then you will see a clickable link to send your log directly from this page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to give it information via the settings page.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If things broke after a new update, please try rebuilding your settings first:&lt;br /&gt;
# Note down your settings&lt;br /&gt;
# On the settings page click &#039;Default&#039; and then click &#039;OK&#039;&lt;br /&gt;
# Rebuid your settings&lt;br /&gt;
# Click OK&lt;br /&gt;
# Restart Kodi&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected after trying the above,&lt;br /&gt;
# From the &#039;General&#039; Settings page:&lt;br /&gt;
## Turn on &#039;Show debugging info in normal log&#039;&lt;br /&gt;
## Click OK&lt;br /&gt;
## Recreate your problem&lt;br /&gt;
## Go back to Settings and on the General page, click to write your settings into the log.&lt;br /&gt;
## Exit Kodi&lt;br /&gt;
# Find your log file: [[Log_file/Advanced#Location|Wiki: Log File Location]]&lt;br /&gt;
# UPLOAD AN &#039;&#039;&#039;ENTIRE&#039;&#039;&#039; COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin]&lt;br /&gt;
# INCLUDE A LINK TO THE LOG IN YOUR POST ON THE FORUM&lt;br /&gt;
&lt;br /&gt;
Please do not turn on Kodi&#039;s debug mode before uploading a log unless asked to do so. This typically just generates more noise in the log, making it harder to pinpoint the problem.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=120026</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=120026"/>
		<updated>2016-03-27T13:43:18Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* FAQs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python, script or json-rpc-notify.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications. This is a json notification receiver event. It is completely separate from the json-rpc-notify TASK which sends notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
If you need to ensure that a space is not split, use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
If you have the [http://addons.kodi.tv/show/script.xbmc.debug.log/ Kodi log uploader addon] installed, then you will see a clickable link to send your log directly from this page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to give it information via the settings page.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If things broke after a new update, please try rebuilding your settings first:&lt;br /&gt;
# Note down your settings&lt;br /&gt;
# On the settings page click &#039;Default&#039; and then click &#039;OK&#039;&lt;br /&gt;
# Rebuid your settings&lt;br /&gt;
# Click OK&lt;br /&gt;
# Restart Kodi&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected after trying the above,&lt;br /&gt;
# From the &#039;General&#039; Settings page:&lt;br /&gt;
## Turn on &#039;Show debugging info in normal log&#039;&lt;br /&gt;
## Click OK&lt;br /&gt;
## Recreate your problem&lt;br /&gt;
## Go back to Settings and on the General page, click to write your settings into the log.&lt;br /&gt;
## Exit Kodi&lt;br /&gt;
# Find your log file: [[Log_file/Advanced#Location|Wiki: Log File Location]]&lt;br /&gt;
# UPLOAD AN &#039;&#039;&#039;ENTIRE&#039;&#039;&#039; COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin]&lt;br /&gt;
# INCLUDE A LINK TO THE LOG IN YOUR POST ON THE FORUM&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=120025</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=120025"/>
		<updated>2016-03-27T13:42:11Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* FAQs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python, script or json-rpc-notify.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications. This is a json notification receiver event. It is completely separate from the json-rpc-notify TASK which sends notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
If you need to ensure that a space is not split, use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
If you have the [http://addons.kodi.tv/show/script.xbmc.debug.log/ Kodi log uploader addon] installed, then you will see a clickable link to send your log directly from this page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to give it information via the settings page.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If things broke after a new update, please try rebuilding your settings first:&lt;br /&gt;
# Note down your settings&lt;br /&gt;
# On the settings page click &#039;Default&#039; and then click &#039;OK&#039;&lt;br /&gt;
# Restart Kodi&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected after trying the above,&lt;br /&gt;
# From the &#039;General&#039; Settings page:&lt;br /&gt;
## Turn on &#039;Show debugging info in normal log&#039;&lt;br /&gt;
## Click OK&lt;br /&gt;
## Recreate your problem&lt;br /&gt;
## Go back to Settings and on the General page, click to write your settings into the log.&lt;br /&gt;
## Exit Kodi&lt;br /&gt;
# Find your log file: [[Log_file/Advanced#Location|Wiki: Log File Location]]&lt;br /&gt;
# UPLOAD AN &#039;&#039;&#039;ENTIRE&#039;&#039;&#039; COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin]&lt;br /&gt;
# INCLUDE A LINK TO THE LOG IN YOUR POST ON THE FORUM&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=120024</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=120024"/>
		<updated>2016-03-27T13:39:27Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* FAQs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python, script or json-rpc-notify.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications. This is a json notification receiver event. It is completely separate from the json-rpc-notify TASK which sends notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
If you need to ensure that a space is not split, use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
If you have the [http://addons.kodi.tv/show/script.xbmc.debug.log/ Kodi log uploader addon] installed, then you will see a clickable link to send your log directly from this page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to give it information via the settings page.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected,&lt;br /&gt;
# From the &#039;General&#039; Settings page:&lt;br /&gt;
## Turn on &#039;Show debugging info in normal log&#039;&lt;br /&gt;
## Click OK&lt;br /&gt;
## Recreate your problem&lt;br /&gt;
## Go back to Settings and on the General page, click to write your settings into the log.&lt;br /&gt;
## Exit Kodi&lt;br /&gt;
# Find your log file: [[Log_file/Advanced#Location|Wiki: Log File Location]]&lt;br /&gt;
# UPLOAD AN &#039;&#039;&#039;ENTIRE&#039;&#039;&#039; COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin]&lt;br /&gt;
# INCLUDE A LINK TO THE LOG IN YOUR POST ON THE FORUM&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117626</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117626"/>
		<updated>2016-03-22T21:18:08Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Settings - Events */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python, script or json-rpc-notify.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications. This is a json notification receiver event. It is completely separate from the json-rpc-notify TASK which sends notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
If you need to ensure that a space is not split, use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
If you have the [http://addons.kodi.tv/show/script.xbmc.debug.log/ Kodi log uploader addon] installed, then you will see a clickable link to send your log directly from this page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to give it information via the settings page.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected, please also UPLOAD A COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin] AND INCLUDE A LINK TO THE LOG IN YOUR POST! ALSO: from the &#039;General&#039; Settings page, 1) Turn on &#039;Show debugging info in normal log&#039; 2) Click to write your settings to the log. This is incredibly helpful for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117625</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117625"/>
		<updated>2016-03-22T21:16:11Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Settings - Tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python, script or json-rpc-notify.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
If you need to ensure that a space is not split, use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
If you have the [http://addons.kodi.tv/show/script.xbmc.debug.log/ Kodi log uploader addon] installed, then you will see a clickable link to send your log directly from this page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to give it information via the settings page.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected, please also UPLOAD A COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin] AND INCLUDE A LINK TO THE LOG IN YOUR POST! ALSO: from the &#039;General&#039; Settings page, 1) Turn on &#039;Show debugging info in normal log&#039; 2) Click to write your settings to the log. This is incredibly helpful for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117624</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117624"/>
		<updated>2016-03-22T21:08:11Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Settings - General */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python or script.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
If you need to ensure that a space is not split, use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
If you have the [http://addons.kodi.tv/show/script.xbmc.debug.log/ Kodi log uploader addon] installed, then you will see a clickable link to send your log directly from this page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to give it information via the settings page.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected, please also UPLOAD A COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin] AND INCLUDE A LINK TO THE LOG IN YOUR POST! ALSO: from the &#039;General&#039; Settings page, 1) Turn on &#039;Show debugging info in normal log&#039; 2) Click to write your settings to the log. This is incredibly helpful for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117623</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117623"/>
		<updated>2016-03-22T21:03:20Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Settings - Update */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python or script.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
If you need to ensure that a space is not split, use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally encountered an error while downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to give it information via the settings page.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected, please also UPLOAD A COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin] AND INCLUDE A LINK TO THE LOG IN YOUR POST! ALSO: from the &#039;General&#039; Settings page, 1) Turn on &#039;Show debugging info in normal log&#039; 2) Click to write your settings to the log. This is incredibly helpful for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117622</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117622"/>
		<updated>2016-03-22T21:01:18Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Settings - Events */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python or script.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 31 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required. This uses the python xbmc.Monitor.OnNotification function. Note that this does not receive ALL notifications.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory. Requires XCODE is installed as well.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
If you need to ensure that a space is not split, use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during  the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally gotten error downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to give it information via the settings page.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected, please also UPLOAD A COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin] AND INCLUDE A LINK TO THE LOG IN YOUR POST! ALSO: from the &#039;General&#039; Settings page, 1) Turn on &#039;Show debugging info in normal log&#039; 2) Click to write your settings to the log. This is incredibly helpful for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117621</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117621"/>
		<updated>2016-03-22T20:58:21Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Settings - Tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python or script.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
&lt;br /&gt;
* For builtins:&lt;br /&gt;
*# See the wiki for a list of functions: [[List_of_built-in_functions]]&lt;br /&gt;
*# Arguments can be passed via userags when configuring the event&lt;br /&gt;
&lt;br /&gt;
* For json notifications:&lt;br /&gt;
*# You can configure the &#039;sender&#039; string to be used during the notification broadcast&lt;br /&gt;
*# Note that all available data is sent in the &#039;data&#039; submessage&#039;, so userargs is not utilized for this task&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 29 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
If you need to ensure that a space is not split, use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during  the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally gotten error downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to give it information via the settings page.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected, please also UPLOAD A COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin] AND INCLUDE A LINK TO THE LOG IN YOUR POST! ALSO: from the &#039;General&#039; Settings page, 1) Turn on &#039;Show debugging info in normal log&#039; 2) Click to write your settings to the log. This is incredibly helpful for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117620</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117620"/>
		<updated>2016-03-22T20:52:52Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Features */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
# Sending a Json-RPC notification&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python or script.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 29 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
If you need to ensure that a space is not split, use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during  the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally gotten error downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to give it information via the settings page.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected, please also UPLOAD A COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin] AND INCLUDE A LINK TO THE LOG IN YOUR POST! ALSO: from the &#039;General&#039; Settings page, 1) Turn on &#039;Show debugging info in normal log&#039; 2) Click to write your settings to the log. This is incredibly helpful for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117479</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117479"/>
		<updated>2016-03-07T16:20:03Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* First steps */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python or script.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 29 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
If you need to ensure that a space is not split, use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during  the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally gotten error downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to give it information via the settings page.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
You would put your own task code in an appropriately named .py file and place it in the following directory: userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected, please also UPLOAD A COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin] AND INCLUDE A LINK TO THE LOG IN YOUR POST! ALSO: from the &#039;General&#039; Settings page, 1) Turn on &#039;Show debugging info in normal log&#039; 2) Click to write your settings to the log. This is incredibly helpful for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117478</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117478"/>
		<updated>2016-03-07T16:18:26Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Features */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the userdata/addon_data/script.service.kodi.callbacks/lib/tasks folder&lt;br /&gt;
** It is better to put user tasks here than in the addon&#039;s tasks folder since that folder may be rewritten during updates&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python or script.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 29 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
If you need to ensure that a space is not split, use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during  the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally gotten error downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to give it information via the settings page.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected, please also UPLOAD A COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin] AND INCLUDE A LINK TO THE LOG IN YOUR POST! ALSO: from the &#039;General&#039; Settings page, 1) Turn on &#039;Show debugging info in normal log&#039; 2) Click to write your settings to the log. This is incredibly helpful for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117467</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117467"/>
		<updated>2016-03-07T12:53:21Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Settings - Update */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the resources/lib/tasks folder&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python or script.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 29 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
If you need to ensure that a space is not split, use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon is not allowed in the official repository, this the need for a separate branch.&lt;br /&gt;
## These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during  the development/testing cycle and are easier to use on keyboardless systems for testing.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally gotten error downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to give it information via the settings page.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected, please also UPLOAD A COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin] AND INCLUDE A LINK TO THE LOG IN YOUR POST! ALSO: from the &#039;General&#039; Settings page, 1) Turn on &#039;Show debugging info in normal log&#039; 2) Click to write your settings to the log. This is incredibly helpful for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117466</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117466"/>
		<updated>2016-03-07T12:51:41Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Settings - Update */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the resources/lib/tasks folder&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python or script.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 29 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
If you need to ensure that a space is not split, use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY (this is the version that is not in the official Kodi repository and must be downloaded and installed manually - may be better if you want to participate in development):&lt;br /&gt;
## Downloading and installing from Github directly in the addon are not allowed in the official repository. These additional functions are useful to developers especially for multiplatform testing. If you want to develop your own task, consider downloading and installing the nonrepo branch.&lt;br /&gt;
## Developers will need to manually edit a couple of lines to point to their own clone on Github. Ask on the forum if you need help with this.&lt;br /&gt;
## The typical install from zip from Kodi will overwrite your directory including anything that you have added including git and development gui settings if they are in the addon directory.&lt;br /&gt;
## These routines will prevent this from happening during  the development/testing cycle.&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally gotten error downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to give it information via the settings page.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected, please also UPLOAD A COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin] AND INCLUDE A LINK TO THE LOG IN YOUR POST! ALSO: from the &#039;General&#039; Settings page, 1) Turn on &#039;Show debugging info in normal log&#039; 2) Click to write your settings to the log. This is incredibly helpful for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117465</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117465"/>
		<updated>2016-03-07T12:44:23Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Settings - Update */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the resources/lib/tasks folder&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python or script.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 29 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
If you need to ensure that a space is not split, use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
# FOR THE NONREPO BRANCH ONLY:&lt;br /&gt;
## The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
## Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
## You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
## You can allow the install to take place silently.&lt;br /&gt;
## You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally gotten error downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to give it information via the settings page.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected, please also UPLOAD A COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin] AND INCLUDE A LINK TO THE LOG IN YOUR POST! ALSO: from the &#039;General&#039; Settings page, 1) Turn on &#039;Show debugging info in normal log&#039; 2) Click to write your settings to the log. This is incredibly helpful for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=File:Kodi-callbacks-settings4-1.PNG&amp;diff=117464</id>
		<title>File:Kodi-callbacks-settings4-1.PNG</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=File:Kodi-callbacks-settings4-1.PNG&amp;diff=117464"/>
		<updated>2016-03-07T12:42:24Z</updated>

		<summary type="html">&lt;p&gt;KenV99: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on_settings&amp;diff=117395</id>
		<title>Add-on settings</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on_settings&amp;diff=117395"/>
		<updated>2016-03-04T17:02:01Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Different types */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{mininav|[[Development]]|[[Add-on development]]}}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{see also|Python development}}&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
settings.xml is a XML file that contains the current configuration for the addon and should be placed in the resources direcory. If your addon has&lt;br /&gt;
configurable items that are set by the user, put them here. This file defines what the user sees&lt;br /&gt;
when they click on Addon settings for your addon. You don&#039;t need to do any coding to utilise this functionality.&lt;br /&gt;
The format for the settings file is relatively straightforward as can be seen in the following example:&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot; standalone=&amp;quot;yes&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;settings&amp;gt;&lt;br /&gt;
    &amp;lt;category label=&amp;quot;32001&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;setting label=&amp;quot;32011&amp;quot; type=&amp;quot;text&amp;quot;   id=&amp;quot;username&amp;quot; default=&amp;quot;&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;setting label=&amp;quot;32012&amp;quot; type=&amp;quot;text&amp;quot;   id=&amp;quot;password&amp;quot; option=&amp;quot;hidden&amp;quot;  enable=&amp;quot;!eq(-1,)&amp;quot; default=&amp;quot;&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;setting label=&amp;quot;32053&amp;quot; type=&amp;quot;slider&amp;quot; id=&amp;quot;limit&amp;quot; subsetting=&amp;quot;true&amp;quot; default=&amp;quot;20&amp;quot; range=&amp;quot;5,5,100&amp;quot; option=&amp;quot;int&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;setting type=&amp;quot;sep&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;setting id=&amp;quot;debug&amp;quot; type=&amp;quot;bool&amp;quot; label=&amp;quot;32013&amp;quot; default=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/category&amp;gt;&lt;br /&gt;
    &amp;lt;category label=&amp;quot;32010&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;setting label=&amp;quot;32032&amp;quot; type=&amp;quot;action&amp;quot; action=&amp;quot;RunScript(my.addon.id, downloadreport)&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/category&amp;gt;&lt;br /&gt;
&amp;lt;/settings&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You need to supply at least one category element.&lt;br /&gt;
The label attribute of both categories and settings should be the id of a language string in your language files or the one of the main Kodi language file.&lt;br /&gt;
&lt;br /&gt;
There are some functionality not cover by this wiki page. See C++ source:&lt;br /&gt;
  https://github.com/xbmc/xbmc/tree/master/xbmc/addons/GUIDialogAddonSettings.cpp&lt;br /&gt;
&lt;br /&gt;
== Different types ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Setting type and additional attributes can be one in the following table:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;prettytable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Type !! Description !! Value attribute (value=&amp;quot;&amp;quot;) !! Notes&lt;br /&gt;
|-&lt;br /&gt;
| music ||  ||  ||&lt;br /&gt;
|-&lt;br /&gt;
| video ||  ||  ||&lt;br /&gt;
|-&lt;br /&gt;
| pictures ||  ||  ||&lt;br /&gt;
|-&lt;br /&gt;
| programs ||  ||  ||&lt;br /&gt;
|-&lt;br /&gt;
| local ||  ||  ||&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Settings can have additional attributes:&#039;&#039;&#039;&lt;br /&gt;
{| class=&amp;quot;prettytable&amp;quot; border=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| source=&amp;quot;&amp;quot; || &amp;quot;video&amp;quot;, &amp;quot;music&amp;quot;, &amp;quot;pictures&amp;quot;, &amp;quot;programs&amp;quot;, &amp;quot;files&amp;quot;, &amp;quot;local&amp;quot; or blank.&amp;quot;&amp;lt;br /&amp;gt;if source is blank it will use the type for shares if it is a valid share if not a valid share it will use, both local and network drives.&lt;br /&gt;
|-&lt;br /&gt;
| visible=&amp;quot;&amp;quot; || &amp;quot;true&amp;quot;, &amp;quot;false&amp;quot; or conditional.&amp;lt;br /&amp;gt;Determines if the setting is displayed in the settings dialog (default = &#039;true&#039;)&amp;quot;&amp;lt;br /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| enable=&amp;quot;&amp;quot; || &amp;quot;true&amp;quot;, &amp;quot;false&amp;quot; or conditional.&amp;lt;br /&amp;gt;Allows you to determine whether this setting should be shown as greyed-out and unable to be changed.&lt;br /&gt;
|-&lt;br /&gt;
| conditionals || 3 comparators are available to allow a setting to be made visible or enabled based on other settings:&lt;br /&gt;
* eq() Equal to&lt;br /&gt;
* gt() Greater than&lt;br /&gt;
* lt() Less than&lt;br /&gt;
&lt;br /&gt;
One can AND the comparators using the + symbol, and OR the comparators using the | symbol. A combination of AND and OR is not currently supported.&lt;br /&gt;
&lt;br /&gt;
One can negate the eq comparator using the ! symbol (e.g. !eq() ).&lt;br /&gt;
&lt;br /&gt;
Each comparator takes 2 operands:&lt;br /&gt;
* Relative position of setting to compare&lt;br /&gt;
* Value to compare against&lt;br /&gt;
&lt;br /&gt;
Thus if we place settings in our file in this order:&lt;br /&gt;
: myFirst setting&lt;br /&gt;
: mySecondSetting&lt;br /&gt;
: myThirdSetting&lt;br /&gt;
&lt;br /&gt;
for the third setting we might add the option:&amp;lt;br /&amp;gt;&lt;br /&gt;
enable=&amp;quot;gt(-2,3) + lt(-2,10)&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
You can also use a conditional statement: enable=&amp;quot;System.HasAddon(plugin.video.youtube)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Comparisons CANNOT be made across category/page boundaries. If one needs to compare to a setting on a different page, a copy of the setting with the same id can be placed on the page where the comparison is to take place and then hidden by setting visible to &#039;false&#039;. The value is automatically updated when the setting on the other page is updated.&lt;br /&gt;
|-&lt;br /&gt;
| subsetting=&amp;quot;true&amp;quot; || Add dash in front of option&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Elements ==&lt;br /&gt;
&lt;br /&gt;
=== Line separators ===&lt;br /&gt;
Line separators add a horizontal separating line between other element. They are purely user-interface elements that do not allow user input and therefore have no meaningful value as a setting.&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;sep&amp;quot; ====&lt;br /&gt;
Shows a horizontal line.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting type=&amp;quot;sep&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;lsep&amp;quot; ====&lt;br /&gt;
Shows a horizontal line with a text.&lt;br /&gt;
&lt;br /&gt;
Attributes:&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32032&amp;quot; type=&amp;quot;lsep&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Text input ===&lt;br /&gt;
Text input elements allow a user to input text in various formats. The &amp;quot;label&amp;quot; attribute must contain an id from the language file that indicates which text to display for the input field.&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;text&amp;quot; ====&lt;br /&gt;
Allow a user to enter one line of text.&lt;br /&gt;
&lt;br /&gt;
Attributes:&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting.&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* option=&amp;quot;hidden&amp;quot;|&amp;quot;urlencoded&amp;quot; (optional)&lt;br /&gt;
:if set to &amp;quot;hidden&amp;quot;, each characters entered by the user will be obfuscated with an asterisks (&amp;quot;*&amp;quot;), as is usual for entering passwords.&lt;br /&gt;
:if set to &amp;quot;urlencoded&amp;quot;, each non-alphanumeric characters entered by the user will be &amp;quot;escaped&amp;quot; using %XX encoding.&lt;br /&gt;
* default=&amp;quot;&#039;&#039;value&#039;&#039;&amp;quot; (optional) - the default value.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32033&amp;quot; type=&amp;quot;text&amp;quot; id=&amp;quot;username&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The value entered by the user is saved as a string value on disk:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;username&amp;quot; value=&amp;quot;john.doe&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{{Note|Security consideration: when using &amp;lt;nowiki&amp;gt;option=&amp;quot;hidden&amp;quot;&amp;lt;/nowiki&amp;gt;, the value entered by the user is still saved as an unencrypted string value on disk.}}&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;ipaddress&amp;quot; ====&lt;br /&gt;
Allow a user to enter an ip address as text.&lt;br /&gt;
&lt;br /&gt;
Attributes:&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting.&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* default=&amp;quot;&#039;&#039;value&#039;&#039;&amp;quot; (optional) - the default value.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32035&amp;quot; type=&amp;quot;ipaddress&amp;quot; id=&amp;quot;ipaddress&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The value entered by the user is saved as a string value on disk:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;ipaddress&amp;quot; value=&amp;quot;127.0.0.1&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Numeric input ===&lt;br /&gt;
Numeric input elements allow a user to enter a number. The &amp;quot;label&amp;quot; attribute must contain an id from the language file that indicates which text to display for the input field.&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;number&amp;quot; ====&lt;br /&gt;
Allows the user to enter an integer using up/down buttons.&lt;br /&gt;
&lt;br /&gt;
Attributes:&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting.&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* default=&amp;quot;&#039;&#039;value&#039;&#039;&amp;quot; (optional) - the default value.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32036&amp;quot; type=&amp;quot;number&amp;quot; id=&amp;quot;code&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The value entered by the user is saved as a string value on disk:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;code&amp;quot; value=&amp;quot;127000&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|In Python, calling xbmcplugin.getSetting will return the number as a string value, which must be converted to an integer value if needed}}&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;slider&amp;quot; ====&lt;br /&gt;
Allows the user to enter a number using a horizontal sliding bar.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32053&amp;quot; type=&amp;quot;slider&amp;quot; id=&amp;quot;limit&amp;quot; default=&amp;quot;20&amp;quot; range=&amp;quot;5,5,100&amp;quot; option=&amp;quot;int&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32053&amp;quot; type=&amp;quot;slider&amp;quot; id=&amp;quot;limit&amp;quot; default=&amp;quot;20&amp;quot; range=&amp;quot;0,100&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Attributes:&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting.&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* &#039;&#039;&#039;range=&amp;quot;&#039;&#039;min&#039;&#039;[,&#039;&#039;step&#039;&#039;],&#039;&#039;max&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - specify the range of valid values.&lt;br /&gt;
* &#039;&#039;&#039;option=&amp;quot;int&amp;quot;|&amp;quot;float&amp;quot;|&amp;quot;percent&amp;quot;&#039;&#039;&#039; (required) - specifies whether to allow the user to choose between integers, floating point numbers or a percentage.&lt;br /&gt;
* default=&amp;quot;&#039;&#039;value&#039;&#039;&amp;quot; (optional) - the default value.&lt;br /&gt;
&lt;br /&gt;
The value entered by the user is saved as a string representation of a floating point value on disk:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;limit&amp;quot; value=&amp;quot;5.000000&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|In Python, calling xbmcplugin.getSetting will return a string, which must be converted to an int, float or percentage value if needed}}&lt;br /&gt;
&lt;br /&gt;
=== Date and time  input ===&lt;br /&gt;
==== type=&amp;quot;date&amp;quot; ====&lt;br /&gt;
Attributes:&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display or string&lt;br /&gt;
* default=&amp;quot;2015-03-12&amp;quot; (optional) - the default value.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;record_date&amp;quot; type=&amp;quot;date&amp;quot; label=&amp;quot;32030&amp;quot; default=&amp;quot;2015-03-12&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;time&amp;quot; ====&lt;br /&gt;
Attributes:&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display or string&lt;br /&gt;
* default=&amp;quot;13:13&amp;quot; (optional) - the default value.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;record_time&amp;quot; type=&amp;quot;time&amp;quot; label=&amp;quot;32031&amp;quot; default=&amp;quot;13:13&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Boolean input ===&lt;br /&gt;
Boolean input elements allow a user to switch a setting on or off.&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;bool&amp;quot; ====&lt;br /&gt;
Attributes:&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* default=&amp;quot;true&amp;quot;|&amp;quot;false&amp;quot; (optional) - the default value.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32033&amp;quot; type=&amp;quot;bool&amp;quot; id=&amp;quot;background&amp;quot; default=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|&amp;quot;true&amp;quot; and &amp;quot;false&amp;quot; are case sensitive!}}&lt;br /&gt;
&lt;br /&gt;
The value entered by the user is saved as a string &amp;quot;true&amp;quot; or &amp;quot;false&amp;quot;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;background&amp;quot; value=&amp;quot;false&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|In Python, calling xbmcplugin.getSetting will return a string &amp;quot;true&amp;quot; or &amp;quot;false&amp;quot;, which must be converted to a boolean value if needed}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Selector ===&lt;br /&gt;
Will open separate selection window &lt;br /&gt;
==== type=&amp;quot;select&amp;quot; ====&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* &#039;&#039;&#039;values=&amp;quot;&#039;&#039;value1&#039;&#039;[|&#039;&#039;value2&#039;&#039;[...]]&amp;quot; - or -&lt;br /&gt;
* &#039;&#039;&#039;lvalues=&amp;quot;&#039;&#039;id1&#039;&#039;[|&#039;&#039;id2&#039;&#039;[...]]&amp;quot; (required): A list of values or language file ids from which the user can choose.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;id_select&amp;quot; type=&amp;quot;select&amp;quot; label=&amp;quot;32000&amp;quot; lvalues=&amp;quot;32001|32002|32003|32004&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;addon&amp;quot; ====&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* &#039;&#039;&#039;addontype=&amp;quot;&#039;&#039;xbmc.metadata.scraper.movies&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - type of addon.&lt;br /&gt;
* multiselect=&amp;quot;&#039;&#039;true|false&#039;&#039;&amp;quot; (optional) - allows to select several addons&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;id_addon&amp;quot; type=&amp;quot;addon&amp;quot; label=&amp;quot;32111&amp;quot; default=&amp;quot;&amp;quot; addontype=&amp;quot;xbmc.metadata.scraper.movies&amp;quot;  multiselect=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rotary selector ===&lt;br /&gt;
A rotary selector allows the user to selected from a list of predefined values. &lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;enum&amp;quot; or &amp;quot;labelenum&amp;quot; ====&lt;br /&gt;
Both element types work the same except that the &amp;quot;enum&amp;quot; type will use the index of the chosen value, wheras the &amp;quot;labelenum&amp;quot; will use the actual value.&lt;br /&gt;
&lt;br /&gt;
Arguments:&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* &#039;&#039;&#039;values=&amp;quot;&#039;&#039;value1&#039;&#039;[|&#039;&#039;value2&#039;&#039;[...]]&amp;quot; - or -&lt;br /&gt;
* &#039;&#039;&#039;lvalues=&amp;quot;&#039;&#039;id1&#039;&#039;[|&#039;&#039;id2&#039;&#039;[...]]&amp;quot; (required):&lt;br /&gt;
: A list of values or language file ids from which the user can choose.&lt;br /&gt;
* values=&amp;quot;$HOURS&amp;quot; is special case to select hour ( works only for type=&amp;quot;enum&amp;quot; )&lt;br /&gt;
* sort=&amp;quot;yes&amp;quot; - sorts labels ( works only for type=&amp;quot;labelenum&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32018&amp;quot; type=&amp;quot;enum&amp;quot; id=&amp;quot;service1&amp;quot; lvalues=&amp;quot;32021|32022|32023|32024&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32020&amp;quot; type=&amp;quot;labelenum&amp;quot; id=&amp;quot;service3&amp;quot; lvalues=&amp;quot;32021|32022|32023|32024&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;EnumHours&amp;quot; type=&amp;quot;enum&amp;quot; id=&amp;quot;default_enumhours&amp;quot; values=&amp;quot;$HOURS&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Selecting the value &amp;quot;One&amp;quot; will return the int value &amp;quot;0&amp;quot;, selecting the value &amp;quot;Two&amp;quot; will return the int value &amp;quot;1&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
The value entered by the user is saved as a string. For &amp;quot;enum&amp;quot;-type settings the index of the value is saved, starting at 0 for the first value. For &amp;quot;labelenum&amp;quot;-type settings the value is saved or, in case the lvalues attribute is used, the label translated in the language of the user.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;service1&amp;quot; value=&amp;quot;0&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;service3&amp;quot; value=&amp;quot;SomethingTranslated&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== File and folder browsing ===&lt;br /&gt;
File and folder browsing elements allow a user to select a file or folder by browsing the local disks or network. You can specify a media type to show only files of the chosen type to the user. The &amp;quot;label&amp;quot; attribute must contain an id from the language file that indicates which text to display for the input field.&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;file&amp;quot;, &amp;quot;audio&amp;quot;, &amp;quot;video&amp;quot;, &amp;quot;image&amp;quot; or &amp;quot;executable&amp;quot; ====&lt;br /&gt;
Allow the user to browse for and select a file. When using type=&amp;quot;audio&amp;quot;, &amp;quot;video&amp;quot;, &amp;quot;image&amp;quot; or &amp;quot;executable&amp;quot;, only files of those types are displayed to the user.&lt;br /&gt;
&lt;br /&gt;
Attributes:&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* value=&amp;quot;&#039;&#039;value&#039;&#039;&amp;quot; (optional) - the default value.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32033&amp;quot; type=&amp;quot;file&amp;quot; id=&amp;quot;file&amp;quot; value=&amp;quot;path_to_files&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The full path to the file selected by the user is saved as a string value on disk:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;file&amp;quot; value=&amp;quot;smb://path_to_files/file.ext&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;folder&amp;quot; ====&lt;br /&gt;
Allow the user to browse for and select a folder.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* source=&amp;quot;auto&amp;quot;|&amp;quot;images&amp;quot;|... (optional, default=&amp;quot;auto&amp;quot;) - select a starting folder for the browse dialog.&amp;lt;!-- There was no additional information on the page when I rewrote it, so I made this assumption - is it correct? What other options are there besides &amp;quot;auto&amp;quot; and &amp;quot;images&amp;quot; --&amp;gt;&lt;br /&gt;
* value=&amp;quot;&#039;&#039;value&#039;&#039;&amp;quot; (optional, default=&amp;quot;&amp;quot;) - the default value.&lt;br /&gt;
* option=&amp;quot;writeable&amp;quot; (optional, default=&amp;quot;&amp;quot;) - the user can be allowed to create and select new folders by setting this argument.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32033&amp;quot; type=&amp;quot;folder&amp;quot; id=&amp;quot;folder&amp;quot; source=&amp;quot;auto&amp;quot; option=&amp;quot;writeable&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The full path to the folder selected by the user is saved as a string value on disk:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;folder&amp;quot; value=&amp;quot;smb://path_to_files/&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;fileenum&amp;quot; ====&lt;br /&gt;
Display files in a folder as an enum selector.&lt;br /&gt;
&lt;br /&gt;
Example: List sub-folders of the &#039;resources&#039; folder for this add-on in the settings.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;myenum&amp;quot; type=&amp;quot;fileenum&amp;quot; values=&amp;quot;resources&amp;quot; mask=&amp;quot;/&amp;quot; &amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Extra attributes ====&lt;br /&gt;
&lt;br /&gt;
* mask=&amp;quot;&#039;&#039;value&#039;&#039;&amp;quot; - filter selectable files. Examples: &amp;quot;/&amp;quot; - display only folders. &amp;quot;*.txt&amp;quot; - display only .txt files.&lt;br /&gt;
* option=&amp;quot;hideext&amp;quot; - hide file extensions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Action execution ===&lt;br /&gt;
==== type = &amp;quot;action&amp;quot; ====&lt;br /&gt;
&lt;br /&gt;
Adds line to configuration windows which allow to execute action&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32032&amp;quot; type=&amp;quot;action&amp;quot; action=&amp;quot;RunScript(my.addon.id, downloadreport)&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of actions that can be used:&lt;br /&gt;
* [[List of built-in functions]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Attributes:&lt;br /&gt;
* option=&amp;quot;close&amp;quot; (close the settings dialog before executing the action)&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons|*]]&lt;br /&gt;
[[Category:Settings]]&lt;br /&gt;
[[Category:Add-on development]]&lt;br /&gt;
[[Category:Skin development]]&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on_settings&amp;diff=117394</id>
		<title>Add-on settings</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on_settings&amp;diff=117394"/>
		<updated>2016-03-04T16:54:37Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Different types */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{mininav|[[Development]]|[[Add-on development]]}}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{see also|Python development}}&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
settings.xml is a XML file that contains the current configuration for the addon and should be placed in the resources direcory. If your addon has&lt;br /&gt;
configurable items that are set by the user, put them here. This file defines what the user sees&lt;br /&gt;
when they click on Addon settings for your addon. You don&#039;t need to do any coding to utilise this functionality.&lt;br /&gt;
The format for the settings file is relatively straightforward as can be seen in the following example:&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot; standalone=&amp;quot;yes&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;settings&amp;gt;&lt;br /&gt;
    &amp;lt;category label=&amp;quot;32001&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;setting label=&amp;quot;32011&amp;quot; type=&amp;quot;text&amp;quot;   id=&amp;quot;username&amp;quot; default=&amp;quot;&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;setting label=&amp;quot;32012&amp;quot; type=&amp;quot;text&amp;quot;   id=&amp;quot;password&amp;quot; option=&amp;quot;hidden&amp;quot;  enable=&amp;quot;!eq(-1,)&amp;quot; default=&amp;quot;&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;setting label=&amp;quot;32053&amp;quot; type=&amp;quot;slider&amp;quot; id=&amp;quot;limit&amp;quot; subsetting=&amp;quot;true&amp;quot; default=&amp;quot;20&amp;quot; range=&amp;quot;5,5,100&amp;quot; option=&amp;quot;int&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;setting type=&amp;quot;sep&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;setting id=&amp;quot;debug&amp;quot; type=&amp;quot;bool&amp;quot; label=&amp;quot;32013&amp;quot; default=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/category&amp;gt;&lt;br /&gt;
    &amp;lt;category label=&amp;quot;32010&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;setting label=&amp;quot;32032&amp;quot; type=&amp;quot;action&amp;quot; action=&amp;quot;RunScript(my.addon.id, downloadreport)&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/category&amp;gt;&lt;br /&gt;
&amp;lt;/settings&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You need to supply at least one category element.&lt;br /&gt;
The label attribute of both categories and settings should be the id of a language string in your language files or the one of the main Kodi language file.&lt;br /&gt;
&lt;br /&gt;
There are some functionality not cover by this wiki page. See C++ source:&lt;br /&gt;
  https://github.com/xbmc/xbmc/tree/master/xbmc/addons/GUIDialogAddonSettings.cpp&lt;br /&gt;
&lt;br /&gt;
== Different types ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Setting type and additional attributes can be one in the following table:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;prettytable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Type !! Description !! Value attribute (value=&amp;quot;&amp;quot;) !! Notes&lt;br /&gt;
|-&lt;br /&gt;
| music ||  ||  ||&lt;br /&gt;
|-&lt;br /&gt;
| video ||  ||  ||&lt;br /&gt;
|-&lt;br /&gt;
| pictures ||  ||  ||&lt;br /&gt;
|-&lt;br /&gt;
| programs ||  ||  ||&lt;br /&gt;
|-&lt;br /&gt;
| local ||  ||  ||&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Settings can have additional attributes:&#039;&#039;&#039;&lt;br /&gt;
{| class=&amp;quot;prettytable&amp;quot; border=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| source=&amp;quot;&amp;quot; || &amp;quot;video&amp;quot;, &amp;quot;music&amp;quot;, &amp;quot;pictures&amp;quot;, &amp;quot;programs&amp;quot;, &amp;quot;files&amp;quot;, &amp;quot;local&amp;quot; or blank.&amp;quot;&amp;lt;br /&amp;gt;if source is blank it will use the type for shares if it is a valid share if not a valid share it will use, both local and network drives.&lt;br /&gt;
|-&lt;br /&gt;
| visible=&amp;quot;&amp;quot; || &amp;quot;true&amp;quot;, &amp;quot;false&amp;quot; or conditional.&amp;lt;br /&amp;gt;Determines if the setting is displayed in the settings dialog (default = &#039;true&#039;)&amp;quot;&amp;lt;br /&amp;gt;You can also use a conditional statement:&amp;lt;br /&amp;gt;visible=&amp;quot;System.HasAddon(plugin.video.youtube)&amp;quot;&amp;lt;br /&amp;gt;visible=&amp;quot;eq(-2,true)&amp;quot; ( same syntax like for enable=&amp;quot;&amp;quot; ) &lt;br /&gt;
|-&lt;br /&gt;
| enable=&amp;quot;&amp;quot; || Allows you to determine whether this setting should be shown based on the value of another setting. 3 comparators are available:&amp;quot;&lt;br /&gt;
* eq() Equal to&lt;br /&gt;
* gt() Greater than&lt;br /&gt;
* lt() Less than&lt;br /&gt;
&lt;br /&gt;
One can AND the comparators using the + symbol, and OR the comparators using the | symbol. A combination of AND and OR is not currently supported.&lt;br /&gt;
&lt;br /&gt;
One negate the eq comparator using the ! symbol (e.g. !eq() ).&lt;br /&gt;
&lt;br /&gt;
Each comparator takes 2 operands:&lt;br /&gt;
* Relative position of setting to compare&lt;br /&gt;
* Value to compare against&lt;br /&gt;
&lt;br /&gt;
Thus if we place settings in our file in this order:&lt;br /&gt;
: myFirst setting&lt;br /&gt;
: mySecondSetting&lt;br /&gt;
: myThirdSetting&lt;br /&gt;
&lt;br /&gt;
for the third setting we might add the option:&amp;lt;br /&amp;gt;&lt;br /&gt;
enable=&amp;quot;gt(-2,3) + lt(-2,10)&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
You can also use a conditional statement: enable=&amp;quot;System.HasAddon(plugin.video.youtube)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Comparisons CANNOT be made across category/page boundaries. If one needs to compare to a setting on a different page, a copy of the setting with the same id can be placed on the page where the comparison is to take place and then hidden by setting visible to &#039;false&#039;.&lt;br /&gt;
|-&lt;br /&gt;
| subsetting=&amp;quot;true&amp;quot; || Add dash in front of option&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Elements ==&lt;br /&gt;
&lt;br /&gt;
=== Line separators ===&lt;br /&gt;
Line separators add a horizontal separating line between other element. They are purely user-interface elements that do not allow user input and therefore have no meaningful value as a setting.&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;sep&amp;quot; ====&lt;br /&gt;
Shows a horizontal line.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting type=&amp;quot;sep&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;lsep&amp;quot; ====&lt;br /&gt;
Shows a horizontal line with a text.&lt;br /&gt;
&lt;br /&gt;
Attributes:&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32032&amp;quot; type=&amp;quot;lsep&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Text input ===&lt;br /&gt;
Text input elements allow a user to input text in various formats. The &amp;quot;label&amp;quot; attribute must contain an id from the language file that indicates which text to display for the input field.&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;text&amp;quot; ====&lt;br /&gt;
Allow a user to enter one line of text.&lt;br /&gt;
&lt;br /&gt;
Attributes:&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting.&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* option=&amp;quot;hidden&amp;quot;|&amp;quot;urlencoded&amp;quot; (optional)&lt;br /&gt;
:if set to &amp;quot;hidden&amp;quot;, each characters entered by the user will be obfuscated with an asterisks (&amp;quot;*&amp;quot;), as is usual for entering passwords.&lt;br /&gt;
:if set to &amp;quot;urlencoded&amp;quot;, each non-alphanumeric characters entered by the user will be &amp;quot;escaped&amp;quot; using %XX encoding.&lt;br /&gt;
* default=&amp;quot;&#039;&#039;value&#039;&#039;&amp;quot; (optional) - the default value.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32033&amp;quot; type=&amp;quot;text&amp;quot; id=&amp;quot;username&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The value entered by the user is saved as a string value on disk:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;username&amp;quot; value=&amp;quot;john.doe&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{{Note|Security consideration: when using &amp;lt;nowiki&amp;gt;option=&amp;quot;hidden&amp;quot;&amp;lt;/nowiki&amp;gt;, the value entered by the user is still saved as an unencrypted string value on disk.}}&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;ipaddress&amp;quot; ====&lt;br /&gt;
Allow a user to enter an ip address as text.&lt;br /&gt;
&lt;br /&gt;
Attributes:&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting.&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* default=&amp;quot;&#039;&#039;value&#039;&#039;&amp;quot; (optional) - the default value.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32035&amp;quot; type=&amp;quot;ipaddress&amp;quot; id=&amp;quot;ipaddress&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The value entered by the user is saved as a string value on disk:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;ipaddress&amp;quot; value=&amp;quot;127.0.0.1&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Numeric input ===&lt;br /&gt;
Numeric input elements allow a user to enter a number. The &amp;quot;label&amp;quot; attribute must contain an id from the language file that indicates which text to display for the input field.&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;number&amp;quot; ====&lt;br /&gt;
Allows the user to enter an integer using up/down buttons.&lt;br /&gt;
&lt;br /&gt;
Attributes:&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting.&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* default=&amp;quot;&#039;&#039;value&#039;&#039;&amp;quot; (optional) - the default value.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32036&amp;quot; type=&amp;quot;number&amp;quot; id=&amp;quot;code&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The value entered by the user is saved as a string value on disk:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;code&amp;quot; value=&amp;quot;127000&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|In Python, calling xbmcplugin.getSetting will return the number as a string value, which must be converted to an integer value if needed}}&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;slider&amp;quot; ====&lt;br /&gt;
Allows the user to enter a number using a horizontal sliding bar.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32053&amp;quot; type=&amp;quot;slider&amp;quot; id=&amp;quot;limit&amp;quot; default=&amp;quot;20&amp;quot; range=&amp;quot;5,5,100&amp;quot; option=&amp;quot;int&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32053&amp;quot; type=&amp;quot;slider&amp;quot; id=&amp;quot;limit&amp;quot; default=&amp;quot;20&amp;quot; range=&amp;quot;0,100&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Attributes:&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting.&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* &#039;&#039;&#039;range=&amp;quot;&#039;&#039;min&#039;&#039;[,&#039;&#039;step&#039;&#039;],&#039;&#039;max&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - specify the range of valid values.&lt;br /&gt;
* &#039;&#039;&#039;option=&amp;quot;int&amp;quot;|&amp;quot;float&amp;quot;|&amp;quot;percent&amp;quot;&#039;&#039;&#039; (required) - specifies whether to allow the user to choose between integers, floating point numbers or a percentage.&lt;br /&gt;
* default=&amp;quot;&#039;&#039;value&#039;&#039;&amp;quot; (optional) - the default value.&lt;br /&gt;
&lt;br /&gt;
The value entered by the user is saved as a string representation of a floating point value on disk:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;limit&amp;quot; value=&amp;quot;5.000000&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|In Python, calling xbmcplugin.getSetting will return a string, which must be converted to an int, float or percentage value if needed}}&lt;br /&gt;
&lt;br /&gt;
=== Date and time  input ===&lt;br /&gt;
==== type=&amp;quot;date&amp;quot; ====&lt;br /&gt;
Attributes:&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display or string&lt;br /&gt;
* default=&amp;quot;2015-03-12&amp;quot; (optional) - the default value.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;record_date&amp;quot; type=&amp;quot;date&amp;quot; label=&amp;quot;32030&amp;quot; default=&amp;quot;2015-03-12&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;time&amp;quot; ====&lt;br /&gt;
Attributes:&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display or string&lt;br /&gt;
* default=&amp;quot;13:13&amp;quot; (optional) - the default value.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;record_time&amp;quot; type=&amp;quot;time&amp;quot; label=&amp;quot;32031&amp;quot; default=&amp;quot;13:13&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Boolean input ===&lt;br /&gt;
Boolean input elements allow a user to switch a setting on or off.&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;bool&amp;quot; ====&lt;br /&gt;
Attributes:&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* default=&amp;quot;true&amp;quot;|&amp;quot;false&amp;quot; (optional) - the default value.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32033&amp;quot; type=&amp;quot;bool&amp;quot; id=&amp;quot;background&amp;quot; default=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|&amp;quot;true&amp;quot; and &amp;quot;false&amp;quot; are case sensitive!}}&lt;br /&gt;
&lt;br /&gt;
The value entered by the user is saved as a string &amp;quot;true&amp;quot; or &amp;quot;false&amp;quot;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;background&amp;quot; value=&amp;quot;false&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|In Python, calling xbmcplugin.getSetting will return a string &amp;quot;true&amp;quot; or &amp;quot;false&amp;quot;, which must be converted to a boolean value if needed}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Selector ===&lt;br /&gt;
Will open separate selection window &lt;br /&gt;
==== type=&amp;quot;select&amp;quot; ====&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* &#039;&#039;&#039;values=&amp;quot;&#039;&#039;value1&#039;&#039;[|&#039;&#039;value2&#039;&#039;[...]]&amp;quot; - or -&lt;br /&gt;
* &#039;&#039;&#039;lvalues=&amp;quot;&#039;&#039;id1&#039;&#039;[|&#039;&#039;id2&#039;&#039;[...]]&amp;quot; (required): A list of values or language file ids from which the user can choose.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;id_select&amp;quot; type=&amp;quot;select&amp;quot; label=&amp;quot;32000&amp;quot; lvalues=&amp;quot;32001|32002|32003|32004&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;addon&amp;quot; ====&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* &#039;&#039;&#039;addontype=&amp;quot;&#039;&#039;xbmc.metadata.scraper.movies&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - type of addon.&lt;br /&gt;
* multiselect=&amp;quot;&#039;&#039;true|false&#039;&#039;&amp;quot; (optional) - allows to select several addons&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;id_addon&amp;quot; type=&amp;quot;addon&amp;quot; label=&amp;quot;32111&amp;quot; default=&amp;quot;&amp;quot; addontype=&amp;quot;xbmc.metadata.scraper.movies&amp;quot;  multiselect=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rotary selector ===&lt;br /&gt;
A rotary selector allows the user to selected from a list of predefined values. &lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;enum&amp;quot; or &amp;quot;labelenum&amp;quot; ====&lt;br /&gt;
Both element types work the same except that the &amp;quot;enum&amp;quot; type will use the index of the chosen value, wheras the &amp;quot;labelenum&amp;quot; will use the actual value.&lt;br /&gt;
&lt;br /&gt;
Arguments:&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* &#039;&#039;&#039;values=&amp;quot;&#039;&#039;value1&#039;&#039;[|&#039;&#039;value2&#039;&#039;[...]]&amp;quot; - or -&lt;br /&gt;
* &#039;&#039;&#039;lvalues=&amp;quot;&#039;&#039;id1&#039;&#039;[|&#039;&#039;id2&#039;&#039;[...]]&amp;quot; (required):&lt;br /&gt;
: A list of values or language file ids from which the user can choose.&lt;br /&gt;
* values=&amp;quot;$HOURS&amp;quot; is special case to select hour ( works only for type=&amp;quot;enum&amp;quot; )&lt;br /&gt;
* sort=&amp;quot;yes&amp;quot; - sorts labels ( works only for type=&amp;quot;labelenum&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32018&amp;quot; type=&amp;quot;enum&amp;quot; id=&amp;quot;service1&amp;quot; lvalues=&amp;quot;32021|32022|32023|32024&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32020&amp;quot; type=&amp;quot;labelenum&amp;quot; id=&amp;quot;service3&amp;quot; lvalues=&amp;quot;32021|32022|32023|32024&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;EnumHours&amp;quot; type=&amp;quot;enum&amp;quot; id=&amp;quot;default_enumhours&amp;quot; values=&amp;quot;$HOURS&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Selecting the value &amp;quot;One&amp;quot; will return the int value &amp;quot;0&amp;quot;, selecting the value &amp;quot;Two&amp;quot; will return the int value &amp;quot;1&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
The value entered by the user is saved as a string. For &amp;quot;enum&amp;quot;-type settings the index of the value is saved, starting at 0 for the first value. For &amp;quot;labelenum&amp;quot;-type settings the value is saved or, in case the lvalues attribute is used, the label translated in the language of the user.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;service1&amp;quot; value=&amp;quot;0&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;service3&amp;quot; value=&amp;quot;SomethingTranslated&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== File and folder browsing ===&lt;br /&gt;
File and folder browsing elements allow a user to select a file or folder by browsing the local disks or network. You can specify a media type to show only files of the chosen type to the user. The &amp;quot;label&amp;quot; attribute must contain an id from the language file that indicates which text to display for the input field.&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;file&amp;quot;, &amp;quot;audio&amp;quot;, &amp;quot;video&amp;quot;, &amp;quot;image&amp;quot; or &amp;quot;executable&amp;quot; ====&lt;br /&gt;
Allow the user to browse for and select a file. When using type=&amp;quot;audio&amp;quot;, &amp;quot;video&amp;quot;, &amp;quot;image&amp;quot; or &amp;quot;executable&amp;quot;, only files of those types are displayed to the user.&lt;br /&gt;
&lt;br /&gt;
Attributes:&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* value=&amp;quot;&#039;&#039;value&#039;&#039;&amp;quot; (optional) - the default value.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32033&amp;quot; type=&amp;quot;file&amp;quot; id=&amp;quot;file&amp;quot; value=&amp;quot;path_to_files&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The full path to the file selected by the user is saved as a string value on disk:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;file&amp;quot; value=&amp;quot;smb://path_to_files/file.ext&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;folder&amp;quot; ====&lt;br /&gt;
Allow the user to browse for and select a folder.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* source=&amp;quot;auto&amp;quot;|&amp;quot;images&amp;quot;|... (optional, default=&amp;quot;auto&amp;quot;) - select a starting folder for the browse dialog.&amp;lt;!-- There was no additional information on the page when I rewrote it, so I made this assumption - is it correct? What other options are there besides &amp;quot;auto&amp;quot; and &amp;quot;images&amp;quot; --&amp;gt;&lt;br /&gt;
* value=&amp;quot;&#039;&#039;value&#039;&#039;&amp;quot; (optional, default=&amp;quot;&amp;quot;) - the default value.&lt;br /&gt;
* option=&amp;quot;writeable&amp;quot; (optional, default=&amp;quot;&amp;quot;) - the user can be allowed to create and select new folders by setting this argument.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32033&amp;quot; type=&amp;quot;folder&amp;quot; id=&amp;quot;folder&amp;quot; source=&amp;quot;auto&amp;quot; option=&amp;quot;writeable&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The full path to the folder selected by the user is saved as a string value on disk:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;folder&amp;quot; value=&amp;quot;smb://path_to_files/&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;fileenum&amp;quot; ====&lt;br /&gt;
Display files in a folder as an enum selector.&lt;br /&gt;
&lt;br /&gt;
Example: List sub-folders of the &#039;resources&#039; folder for this add-on in the settings.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;myenum&amp;quot; type=&amp;quot;fileenum&amp;quot; values=&amp;quot;resources&amp;quot; mask=&amp;quot;/&amp;quot; &amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Extra attributes ====&lt;br /&gt;
&lt;br /&gt;
* mask=&amp;quot;&#039;&#039;value&#039;&#039;&amp;quot; - filter selectable files. Examples: &amp;quot;/&amp;quot; - display only folders. &amp;quot;*.txt&amp;quot; - display only .txt files.&lt;br /&gt;
* option=&amp;quot;hideext&amp;quot; - hide file extensions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Action execution ===&lt;br /&gt;
==== type = &amp;quot;action&amp;quot; ====&lt;br /&gt;
&lt;br /&gt;
Adds line to configuration windows which allow to execute action&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32032&amp;quot; type=&amp;quot;action&amp;quot; action=&amp;quot;RunScript(my.addon.id, downloadreport)&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of actions that can be used:&lt;br /&gt;
* [[List of built-in functions]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Attributes:&lt;br /&gt;
* option=&amp;quot;close&amp;quot; (close the settings dialog before executing the action)&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons|*]]&lt;br /&gt;
[[Category:Settings]]&lt;br /&gt;
[[Category:Add-on development]]&lt;br /&gt;
[[Category:Skin development]]&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on_settings&amp;diff=117393</id>
		<title>Add-on settings</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on_settings&amp;diff=117393"/>
		<updated>2016-03-04T16:53:27Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Different types */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{mininav|[[Development]]|[[Add-on development]]}}&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{see also|Python development}}&lt;br /&gt;
&lt;br /&gt;
== Description ==&lt;br /&gt;
&lt;br /&gt;
settings.xml is a XML file that contains the current configuration for the addon and should be placed in the resources direcory. If your addon has&lt;br /&gt;
configurable items that are set by the user, put them here. This file defines what the user sees&lt;br /&gt;
when they click on Addon settings for your addon. You don&#039;t need to do any coding to utilise this functionality.&lt;br /&gt;
The format for the settings file is relatively straightforward as can be seen in the following example:&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot; standalone=&amp;quot;yes&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;settings&amp;gt;&lt;br /&gt;
    &amp;lt;category label=&amp;quot;32001&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;setting label=&amp;quot;32011&amp;quot; type=&amp;quot;text&amp;quot;   id=&amp;quot;username&amp;quot; default=&amp;quot;&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;setting label=&amp;quot;32012&amp;quot; type=&amp;quot;text&amp;quot;   id=&amp;quot;password&amp;quot; option=&amp;quot;hidden&amp;quot;  enable=&amp;quot;!eq(-1,)&amp;quot; default=&amp;quot;&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;setting label=&amp;quot;32053&amp;quot; type=&amp;quot;slider&amp;quot; id=&amp;quot;limit&amp;quot; subsetting=&amp;quot;true&amp;quot; default=&amp;quot;20&amp;quot; range=&amp;quot;5,5,100&amp;quot; option=&amp;quot;int&amp;quot; /&amp;gt;&lt;br /&gt;
        &amp;lt;setting type=&amp;quot;sep&amp;quot;/&amp;gt;&lt;br /&gt;
        &amp;lt;setting id=&amp;quot;debug&amp;quot; type=&amp;quot;bool&amp;quot; label=&amp;quot;32013&amp;quot; default=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/category&amp;gt;&lt;br /&gt;
    &amp;lt;category label=&amp;quot;32010&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;setting label=&amp;quot;32032&amp;quot; type=&amp;quot;action&amp;quot; action=&amp;quot;RunScript(my.addon.id, downloadreport)&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/category&amp;gt;&lt;br /&gt;
&amp;lt;/settings&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You need to supply at least one category element.&lt;br /&gt;
The label attribute of both categories and settings should be the id of a language string in your language files or the one of the main Kodi language file.&lt;br /&gt;
&lt;br /&gt;
There are some functionality not cover by this wiki page. See C++ source:&lt;br /&gt;
  https://github.com/xbmc/xbmc/tree/master/xbmc/addons/GUIDialogAddonSettings.cpp&lt;br /&gt;
&lt;br /&gt;
== Different types ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Setting type and additional attributes can be one in the following table:&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;prettytable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Type !! Description !! Value attribute (value=&amp;quot;&amp;quot;) !! Notes&lt;br /&gt;
|-&lt;br /&gt;
| music ||  ||  ||&lt;br /&gt;
|-&lt;br /&gt;
| video ||  ||  ||&lt;br /&gt;
|-&lt;br /&gt;
| pictures ||  ||  ||&lt;br /&gt;
|-&lt;br /&gt;
| programs ||  ||  ||&lt;br /&gt;
|-&lt;br /&gt;
| local ||  ||  ||&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Settings can have additional attributes:&#039;&#039;&#039;&lt;br /&gt;
{| class=&amp;quot;prettytable&amp;quot; border=&amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| source=&amp;quot;&amp;quot; || &amp;quot;video&amp;quot;, &amp;quot;music&amp;quot;, &amp;quot;pictures&amp;quot;, &amp;quot;programs&amp;quot;, &amp;quot;files&amp;quot;, &amp;quot;local&amp;quot; or blank.&amp;quot;&amp;lt;br /&amp;gt;if source is blank it will use the type for shares if it is a valid share if not a valid share it will use, both local and network drives.&lt;br /&gt;
|-&lt;br /&gt;
| visible=&amp;quot;&amp;quot; || &amp;quot;true&amp;quot;, &amp;quot;false&amp;quot; or conditional.&amp;lt;br /&amp;gt;Determines if the setting is displayed in the settings dialog (default = &#039;true&#039;)&amp;quot;&amp;lt;br /&amp;gt;You can also use a conditional statement:&amp;lt;br /&amp;gt;visible=&amp;quot;System.HasAddon(plugin.video.youtube)&amp;quot;&amp;lt;br /&amp;gt;visible=&amp;quot;eq(-2,true)&amp;quot; ( same syntax like for enable=&amp;quot;&amp;quot; ) &lt;br /&gt;
|-&lt;br /&gt;
| enable=&amp;quot;&amp;quot; || Allows you to determine whether this setting should be shown based on the value of another setting. 3 comparators are available:&amp;quot;&lt;br /&gt;
* eq() Equal to&lt;br /&gt;
* gt() Greater than&lt;br /&gt;
* lt() Less than&lt;br /&gt;
&lt;br /&gt;
One can AND the comparators using the + symbol, and OR the comparators using the | symbol.&lt;br /&gt;
&lt;br /&gt;
One negate the eq comparator using the ! symbol (e.g. !eq() ).&lt;br /&gt;
&lt;br /&gt;
Each comparator takes 2 operands:&lt;br /&gt;
* Relative position of setting to compare&lt;br /&gt;
* Value to compare against&lt;br /&gt;
&lt;br /&gt;
Thus if we place settings in our file in this order:&lt;br /&gt;
: myFirst setting&lt;br /&gt;
: mySecondSetting&lt;br /&gt;
: myThirdSetting&lt;br /&gt;
&lt;br /&gt;
for the third setting we might add the option:&amp;lt;br /&amp;gt;&lt;br /&gt;
enable=&amp;quot;gt(-2,3) + lt(-2,10)&amp;quot;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
You can also use a conditional statement: enable=&amp;quot;System.HasAddon(plugin.video.youtube)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Comparisons CANNOT be made across category/page boundaries. If one needs to compare to a setting on a different page, a copy of the setting with the same id can be placed on the page where the comparison is to take place and then hidden by setting visible to &#039;false&#039;.&lt;br /&gt;
|-&lt;br /&gt;
| subsetting=&amp;quot;true&amp;quot; || Add dash in front of option&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Elements ==&lt;br /&gt;
&lt;br /&gt;
=== Line separators ===&lt;br /&gt;
Line separators add a horizontal separating line between other element. They are purely user-interface elements that do not allow user input and therefore have no meaningful value as a setting.&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;sep&amp;quot; ====&lt;br /&gt;
Shows a horizontal line.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting type=&amp;quot;sep&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;lsep&amp;quot; ====&lt;br /&gt;
Shows a horizontal line with a text.&lt;br /&gt;
&lt;br /&gt;
Attributes:&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32032&amp;quot; type=&amp;quot;lsep&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Text input ===&lt;br /&gt;
Text input elements allow a user to input text in various formats. The &amp;quot;label&amp;quot; attribute must contain an id from the language file that indicates which text to display for the input field.&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;text&amp;quot; ====&lt;br /&gt;
Allow a user to enter one line of text.&lt;br /&gt;
&lt;br /&gt;
Attributes:&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting.&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* option=&amp;quot;hidden&amp;quot;|&amp;quot;urlencoded&amp;quot; (optional)&lt;br /&gt;
:if set to &amp;quot;hidden&amp;quot;, each characters entered by the user will be obfuscated with an asterisks (&amp;quot;*&amp;quot;), as is usual for entering passwords.&lt;br /&gt;
:if set to &amp;quot;urlencoded&amp;quot;, each non-alphanumeric characters entered by the user will be &amp;quot;escaped&amp;quot; using %XX encoding.&lt;br /&gt;
* default=&amp;quot;&#039;&#039;value&#039;&#039;&amp;quot; (optional) - the default value.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32033&amp;quot; type=&amp;quot;text&amp;quot; id=&amp;quot;username&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The value entered by the user is saved as a string value on disk:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;username&amp;quot; value=&amp;quot;john.doe&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{{Note|Security consideration: when using &amp;lt;nowiki&amp;gt;option=&amp;quot;hidden&amp;quot;&amp;lt;/nowiki&amp;gt;, the value entered by the user is still saved as an unencrypted string value on disk.}}&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;ipaddress&amp;quot; ====&lt;br /&gt;
Allow a user to enter an ip address as text.&lt;br /&gt;
&lt;br /&gt;
Attributes:&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting.&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* default=&amp;quot;&#039;&#039;value&#039;&#039;&amp;quot; (optional) - the default value.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32035&amp;quot; type=&amp;quot;ipaddress&amp;quot; id=&amp;quot;ipaddress&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The value entered by the user is saved as a string value on disk:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;ipaddress&amp;quot; value=&amp;quot;127.0.0.1&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Numeric input ===&lt;br /&gt;
Numeric input elements allow a user to enter a number. The &amp;quot;label&amp;quot; attribute must contain an id from the language file that indicates which text to display for the input field.&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;number&amp;quot; ====&lt;br /&gt;
Allows the user to enter an integer using up/down buttons.&lt;br /&gt;
&lt;br /&gt;
Attributes:&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting.&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* default=&amp;quot;&#039;&#039;value&#039;&#039;&amp;quot; (optional) - the default value.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32036&amp;quot; type=&amp;quot;number&amp;quot; id=&amp;quot;code&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The value entered by the user is saved as a string value on disk:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;code&amp;quot; value=&amp;quot;127000&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|In Python, calling xbmcplugin.getSetting will return the number as a string value, which must be converted to an integer value if needed}}&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;slider&amp;quot; ====&lt;br /&gt;
Allows the user to enter a number using a horizontal sliding bar.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32053&amp;quot; type=&amp;quot;slider&amp;quot; id=&amp;quot;limit&amp;quot; default=&amp;quot;20&amp;quot; range=&amp;quot;5,5,100&amp;quot; option=&amp;quot;int&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32053&amp;quot; type=&amp;quot;slider&amp;quot; id=&amp;quot;limit&amp;quot; default=&amp;quot;20&amp;quot; range=&amp;quot;0,100&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Attributes:&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting.&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* &#039;&#039;&#039;range=&amp;quot;&#039;&#039;min&#039;&#039;[,&#039;&#039;step&#039;&#039;],&#039;&#039;max&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - specify the range of valid values.&lt;br /&gt;
* &#039;&#039;&#039;option=&amp;quot;int&amp;quot;|&amp;quot;float&amp;quot;|&amp;quot;percent&amp;quot;&#039;&#039;&#039; (required) - specifies whether to allow the user to choose between integers, floating point numbers or a percentage.&lt;br /&gt;
* default=&amp;quot;&#039;&#039;value&#039;&#039;&amp;quot; (optional) - the default value.&lt;br /&gt;
&lt;br /&gt;
The value entered by the user is saved as a string representation of a floating point value on disk:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;limit&amp;quot; value=&amp;quot;5.000000&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|In Python, calling xbmcplugin.getSetting will return a string, which must be converted to an int, float or percentage value if needed}}&lt;br /&gt;
&lt;br /&gt;
=== Date and time  input ===&lt;br /&gt;
==== type=&amp;quot;date&amp;quot; ====&lt;br /&gt;
Attributes:&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display or string&lt;br /&gt;
* default=&amp;quot;2015-03-12&amp;quot; (optional) - the default value.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;record_date&amp;quot; type=&amp;quot;date&amp;quot; label=&amp;quot;32030&amp;quot; default=&amp;quot;2015-03-12&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;time&amp;quot; ====&lt;br /&gt;
Attributes:&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display or string&lt;br /&gt;
* default=&amp;quot;13:13&amp;quot; (optional) - the default value.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;record_time&amp;quot; type=&amp;quot;time&amp;quot; label=&amp;quot;32031&amp;quot; default=&amp;quot;13:13&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Boolean input ===&lt;br /&gt;
Boolean input elements allow a user to switch a setting on or off.&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;bool&amp;quot; ====&lt;br /&gt;
Attributes:&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* default=&amp;quot;true&amp;quot;|&amp;quot;false&amp;quot; (optional) - the default value.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32033&amp;quot; type=&amp;quot;bool&amp;quot; id=&amp;quot;background&amp;quot; default=&amp;quot;false&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|&amp;quot;true&amp;quot; and &amp;quot;false&amp;quot; are case sensitive!}}&lt;br /&gt;
&lt;br /&gt;
The value entered by the user is saved as a string &amp;quot;true&amp;quot; or &amp;quot;false&amp;quot;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;background&amp;quot; value=&amp;quot;false&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|In Python, calling xbmcplugin.getSetting will return a string &amp;quot;true&amp;quot; or &amp;quot;false&amp;quot;, which must be converted to a boolean value if needed}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Selector ===&lt;br /&gt;
Will open separate selection window &lt;br /&gt;
==== type=&amp;quot;select&amp;quot; ====&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* &#039;&#039;&#039;values=&amp;quot;&#039;&#039;value1&#039;&#039;[|&#039;&#039;value2&#039;&#039;[...]]&amp;quot; - or -&lt;br /&gt;
* &#039;&#039;&#039;lvalues=&amp;quot;&#039;&#039;id1&#039;&#039;[|&#039;&#039;id2&#039;&#039;[...]]&amp;quot; (required): A list of values or language file ids from which the user can choose.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;id_select&amp;quot; type=&amp;quot;select&amp;quot; label=&amp;quot;32000&amp;quot; lvalues=&amp;quot;32001|32002|32003|32004&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;addon&amp;quot; ====&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* &#039;&#039;&#039;addontype=&amp;quot;&#039;&#039;xbmc.metadata.scraper.movies&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - type of addon.&lt;br /&gt;
* multiselect=&amp;quot;&#039;&#039;true|false&#039;&#039;&amp;quot; (optional) - allows to select several addons&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;id_addon&amp;quot; type=&amp;quot;addon&amp;quot; label=&amp;quot;32111&amp;quot; default=&amp;quot;&amp;quot; addontype=&amp;quot;xbmc.metadata.scraper.movies&amp;quot;  multiselect=&amp;quot;true&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rotary selector ===&lt;br /&gt;
A rotary selector allows the user to selected from a list of predefined values. &lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;enum&amp;quot; or &amp;quot;labelenum&amp;quot; ====&lt;br /&gt;
Both element types work the same except that the &amp;quot;enum&amp;quot; type will use the index of the chosen value, wheras the &amp;quot;labelenum&amp;quot; will use the actual value.&lt;br /&gt;
&lt;br /&gt;
Arguments:&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* &#039;&#039;&#039;values=&amp;quot;&#039;&#039;value1&#039;&#039;[|&#039;&#039;value2&#039;&#039;[...]]&amp;quot; - or -&lt;br /&gt;
* &#039;&#039;&#039;lvalues=&amp;quot;&#039;&#039;id1&#039;&#039;[|&#039;&#039;id2&#039;&#039;[...]]&amp;quot; (required):&lt;br /&gt;
: A list of values or language file ids from which the user can choose.&lt;br /&gt;
* values=&amp;quot;$HOURS&amp;quot; is special case to select hour ( works only for type=&amp;quot;enum&amp;quot; )&lt;br /&gt;
* sort=&amp;quot;yes&amp;quot; - sorts labels ( works only for type=&amp;quot;labelenum&amp;quot; )&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32018&amp;quot; type=&amp;quot;enum&amp;quot; id=&amp;quot;service1&amp;quot; lvalues=&amp;quot;32021|32022|32023|32024&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32020&amp;quot; type=&amp;quot;labelenum&amp;quot; id=&amp;quot;service3&amp;quot; lvalues=&amp;quot;32021|32022|32023|32024&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;EnumHours&amp;quot; type=&amp;quot;enum&amp;quot; id=&amp;quot;default_enumhours&amp;quot; values=&amp;quot;$HOURS&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Selecting the value &amp;quot;One&amp;quot; will return the int value &amp;quot;0&amp;quot;, selecting the value &amp;quot;Two&amp;quot; will return the int value &amp;quot;1&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
The value entered by the user is saved as a string. For &amp;quot;enum&amp;quot;-type settings the index of the value is saved, starting at 0 for the first value. For &amp;quot;labelenum&amp;quot;-type settings the value is saved or, in case the lvalues attribute is used, the label translated in the language of the user.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;service1&amp;quot; value=&amp;quot;0&amp;quot; /&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;service3&amp;quot; value=&amp;quot;SomethingTranslated&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== File and folder browsing ===&lt;br /&gt;
File and folder browsing elements allow a user to select a file or folder by browsing the local disks or network. You can specify a media type to show only files of the chosen type to the user. The &amp;quot;label&amp;quot; attribute must contain an id from the language file that indicates which text to display for the input field.&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;file&amp;quot;, &amp;quot;audio&amp;quot;, &amp;quot;video&amp;quot;, &amp;quot;image&amp;quot; or &amp;quot;executable&amp;quot; ====&lt;br /&gt;
Allow the user to browse for and select a file. When using type=&amp;quot;audio&amp;quot;, &amp;quot;video&amp;quot;, &amp;quot;image&amp;quot; or &amp;quot;executable&amp;quot;, only files of those types are displayed to the user.&lt;br /&gt;
&lt;br /&gt;
Attributes:&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* value=&amp;quot;&#039;&#039;value&#039;&#039;&amp;quot; (optional) - the default value.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32033&amp;quot; type=&amp;quot;file&amp;quot; id=&amp;quot;file&amp;quot; value=&amp;quot;path_to_files&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The full path to the file selected by the user is saved as a string value on disk:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;file&amp;quot; value=&amp;quot;smb://path_to_files/file.ext&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;folder&amp;quot; ====&lt;br /&gt;
Allow the user to browse for and select a folder.&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;id=&amp;quot;&#039;&#039;string&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - the name of the setting&lt;br /&gt;
* &#039;&#039;&#039;label=&amp;quot;&#039;&#039;id&#039;&#039;&amp;quot;&#039;&#039;&#039; (required) - an id from the language file that indicates which text to display.&lt;br /&gt;
* source=&amp;quot;auto&amp;quot;|&amp;quot;images&amp;quot;|... (optional, default=&amp;quot;auto&amp;quot;) - select a starting folder for the browse dialog.&amp;lt;!-- There was no additional information on the page when I rewrote it, so I made this assumption - is it correct? What other options are there besides &amp;quot;auto&amp;quot; and &amp;quot;images&amp;quot; --&amp;gt;&lt;br /&gt;
* value=&amp;quot;&#039;&#039;value&#039;&#039;&amp;quot; (optional, default=&amp;quot;&amp;quot;) - the default value.&lt;br /&gt;
* option=&amp;quot;writeable&amp;quot; (optional, default=&amp;quot;&amp;quot;) - the user can be allowed to create and select new folders by setting this argument.&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32033&amp;quot; type=&amp;quot;folder&amp;quot; id=&amp;quot;folder&amp;quot; source=&amp;quot;auto&amp;quot; option=&amp;quot;writeable&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The full path to the folder selected by the user is saved as a string value on disk:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;folder&amp;quot; value=&amp;quot;smb://path_to_files/&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== type=&amp;quot;fileenum&amp;quot; ====&lt;br /&gt;
Display files in a folder as an enum selector.&lt;br /&gt;
&lt;br /&gt;
Example: List sub-folders of the &#039;resources&#039; folder for this add-on in the settings.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting id=&amp;quot;myenum&amp;quot; type=&amp;quot;fileenum&amp;quot; values=&amp;quot;resources&amp;quot; mask=&amp;quot;/&amp;quot; &amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Extra attributes ====&lt;br /&gt;
&lt;br /&gt;
* mask=&amp;quot;&#039;&#039;value&#039;&#039;&amp;quot; - filter selectable files. Examples: &amp;quot;/&amp;quot; - display only folders. &amp;quot;*.txt&amp;quot; - display only .txt files.&lt;br /&gt;
* option=&amp;quot;hideext&amp;quot; - hide file extensions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Action execution ===&lt;br /&gt;
==== type = &amp;quot;action&amp;quot; ====&lt;br /&gt;
&lt;br /&gt;
Adds line to configuration windows which allow to execute action&lt;br /&gt;
&lt;br /&gt;
Example code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot; enclose=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;setting label=&amp;quot;32032&amp;quot; type=&amp;quot;action&amp;quot; action=&amp;quot;RunScript(my.addon.id, downloadreport)&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
List of actions that can be used:&lt;br /&gt;
* [[List of built-in functions]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Attributes:&lt;br /&gt;
* option=&amp;quot;close&amp;quot; (close the settings dialog before executing the action)&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons|*]]&lt;br /&gt;
[[Category:Settings]]&lt;br /&gt;
[[Category:Add-on development]]&lt;br /&gt;
[[Category:Skin development]]&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117342</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117342"/>
		<updated>2016-02-28T23:36:59Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* FAQs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the resources/lib/tasks folder&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python or script.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 29 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
If you need to ensure that a space is not split, use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
&lt;br /&gt;
# The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
# Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
# You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
# You can allow the install to take place silently.&lt;br /&gt;
# You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally gotten error downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to give it information via the settings page.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
If all else fails, try looking in the log to see if something specific is written there when whatever it is that you are trying to detect occurs and then use the onLogSimple or onLogRegex events to detect your event.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected, please also UPLOAD A COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin] AND INCLUDE A LINK TO THE LOG IN YOUR POST! ALSO: from the &#039;General&#039; Settings page, 1) Turn on &#039;Show debugging info in normal log&#039; 2) Click to write your settings to the log. This is incredibly helpful for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117341</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117341"/>
		<updated>2016-02-28T23:31:41Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Features */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[Add-on:Kodi_Callbacks#List_of_events|jump to list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the resources/lib/tasks folder&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python or script.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 29 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
If you need to ensure that a space is not split, use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
&lt;br /&gt;
# The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
# Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
# You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
# You can allow the install to take place silently.&lt;br /&gt;
# You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally gotten error downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to give it information via the settings page.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected, please also UPLOAD A COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin] AND INCLUDE A LINK TO THE LOG IN YOUR POST! ALSO: from the &#039;General&#039; Settings page, click to write your settings to the log. This is incredibly helpful for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117340</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117340"/>
		<updated>2016-02-28T23:30:11Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Features */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi (jump to [[Add-on:Kodi_Callbacks#List_of_events|list]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the resources/lib/tasks folder&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python or script.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 29 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
If you need to ensure that a space is not split, use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
&lt;br /&gt;
# The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
# Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
# You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
# You can allow the install to take place silently.&lt;br /&gt;
# You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally gotten error downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to give it information via the settings page.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected, please also UPLOAD A COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin] AND INCLUDE A LINK TO THE LOG IN YOUR POST! ALSO: from the &#039;General&#039; Settings page, click to write your settings to the log. This is incredibly helpful for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117339</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117339"/>
		<updated>2016-02-28T23:29:25Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Features */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi [[Add-on:Kodi_Callbacks#List_of_events|list]]&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the resources/lib/tasks folder&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python or script.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 29 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
If you need to ensure that a space is not split, use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
&lt;br /&gt;
# The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
# Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
# You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
# You can allow the install to take place silently.&lt;br /&gt;
# You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally gotten error downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to give it information via the settings page.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected, please also UPLOAD A COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin] AND INCLUDE A LINK TO THE LOG IN YOUR POST! ALSO: from the &#039;General&#039; Settings page, click to write your settings to the log. This is incredibly helpful for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117338</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117338"/>
		<updated>2016-02-28T23:28:40Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Features */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi [[Add-on:Kodi_Callbacks#List_of_events]]&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the resources/lib/tasks folder&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python or script.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 29 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
If you need to ensure that a space is not split, use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
&lt;br /&gt;
# The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
# Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
# You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
# You can allow the install to take place silently.&lt;br /&gt;
# You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally gotten error downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to give it information via the settings page.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected, please also UPLOAD A COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin] AND INCLUDE A LINK TO THE LOG IN YOUR POST! ALSO: from the &#039;General&#039; Settings page, click to write your settings to the log. This is incredibly helpful for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117337</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117337"/>
		<updated>2016-02-28T23:23:03Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Features */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi ([[http://kodi.wiki/view/Add-on:Kodi_Callbacks#List_of_events|list of events]])&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the resources/lib/tasks folder&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python or script.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 29 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
If you need to ensure that a space is not split, use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
&lt;br /&gt;
# The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
# Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
# You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
# You can allow the install to take place silently.&lt;br /&gt;
# You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally gotten error downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to give it information via the settings page.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected, please also UPLOAD A COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin] AND INCLUDE A LINK TO THE LOG IN YOUR POST! ALSO: from the &#039;General&#039; Settings page, click to write your settings to the log. This is incredibly helpful for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117336</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117336"/>
		<updated>2016-02-28T23:21:48Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Features */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi [[http://kodi.wiki/view/Add-on:Kodi_Callbacks#List_of_events|(jump to list of events)]]&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the resources/lib/tasks folder&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python or script.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 29 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
If you need to ensure that a space is not split, use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
&lt;br /&gt;
# The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
# Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
# You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
# You can allow the install to take place silently.&lt;br /&gt;
# You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally gotten error downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to give it information via the settings page.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected, please also UPLOAD A COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin] AND INCLUDE A LINK TO THE LOG IN YOUR POST! ALSO: from the &#039;General&#039; Settings page, click to write your settings to the log. This is incredibly helpful for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
	<entry>
		<id>https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117335</id>
		<title>Add-on:Kodi Callbacks</title>
		<link rel="alternate" type="text/html" href="https://kodi.wiki/index.php?title=Add-on:Kodi_Callbacks&amp;diff=117335"/>
		<updated>2016-02-28T23:14:10Z</updated>

		<summary type="html">&lt;p&gt;KenV99: /* Argument variable substitution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
{{Addon &lt;br /&gt;
|Name=Kodi Callbacks&lt;br /&gt;
|provider-name=KenV99&lt;br /&gt;
|ID=service.kodi.callbacks&lt;br /&gt;
|latest-version=0.9.8&lt;br /&gt;
|extension point=xbmc.service&lt;br /&gt;
|provides=&lt;br /&gt;
|Summary=Callbacks for Kodi Events to launch user tasks&lt;br /&gt;
|Description=Perform custom user-defined tasks for multiple events in Kodi&lt;br /&gt;
    &lt;br /&gt;
|Platform=all&lt;br /&gt;
|Language=&lt;br /&gt;
|License=GNU GENERAL PUBLIC LICENSE. Version 3, June 2007&lt;br /&gt;
|Forum=http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
|Source=https://github.com/KenV99/service.kodi.callbacks&lt;br /&gt;
|Email=&lt;br /&gt;
|broken=&lt;br /&gt;
}}&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Features&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
* Runs as a service when Kodi starts&lt;br /&gt;
* Runs user configured tasks when events occur in Kodi&lt;br /&gt;
* Currently can create tasks for:&lt;br /&gt;
# Running an external script with or without the shell&lt;br /&gt;
# Running an external python script either directly or via dynamic import&lt;br /&gt;
# Running a Kodi builtin&lt;br /&gt;
# Sending an http string (response)&lt;br /&gt;
* Utilizes a simple substitution language so that runtime arguments can be mixed with static user-defined elements to send to the external file as arguments&lt;br /&gt;
* 31 different Kodi events are supported&lt;br /&gt;
* Tasks can be tested directly from the Settings page with direct user feedback for troubleshooting&lt;br /&gt;
* New tasks can be created and shared with others by subclassing an abstract base class and then placing the file in the resources/lib/tasks folder&lt;br /&gt;
* Credit to Yesudeep Mangalapilly (gorakhargosh on github) and contributors for watchdog and pathtools modules.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Installation&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
The script is not currently available via the official repo but has been submitted as of 27-02-2016.&lt;br /&gt;
You can download the zip file and manually copy it to the Kodi Add-Ons folder, overwriting the previous version.&amp;lt;br /&amp;gt;&lt;br /&gt;
Or after download you can load it via the settings addon &#039;install from zip&#039; action.&amp;lt;br /&amp;gt;&lt;br /&gt;
The most recent version of the script can be downloaded here: https://github.com/KenV99/service.kodi.callbacks/archive/master.zip&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
To manually install the script, first unzip the script to a convenient, temporary location and then copy the entire directory named ‘service.kodi.callbacks-master’ with its structure intact to the Kodi addons directory. In windows, this is typically located on your system drive at &#039;Users/Username/AppData/Roaming/Kodi/addons/&#039;. If you have a previous installation, consider backing it up to a safe place before installing.&lt;br /&gt;
&lt;br /&gt;
Remove the &#039;-master&#039; from the end of the folder name!!!&lt;br /&gt;
&lt;br /&gt;
If you are replacing xbmc.callbacks2 which will no longer be developed, the settings from there are not compatible. Copy your settings over to the new addon and then disable or delete xbmc.callbacks2&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Configuration&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
In Kodi go to System &amp;gt; Add-Ons &amp;gt; Enabled Add-Ons &amp;gt; Services &amp;gt; Kodi Callbacks &amp;gt; Configure&lt;br /&gt;
&lt;br /&gt;
In general:&lt;br /&gt;
# Configure your task.&lt;br /&gt;
# On the next page, associate your task with one or more events.&lt;br /&gt;
# Click OK to save.&lt;br /&gt;
# Re-enter settings by clicking configure.&lt;br /&gt;
# Test your setup via the settings page.&lt;br /&gt;
# Re-test by triggering your event if possible.&lt;br /&gt;
&lt;br /&gt;
=== Details ===&lt;br /&gt;
&lt;br /&gt;
There are four pages of settings - Tasks, Events, General and Update&lt;br /&gt;
&lt;br /&gt;
==== Settings - Tasks ====&lt;br /&gt;
[[File:Kodi-callbacks-settings1-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 tasks.&lt;br /&gt;
&lt;br /&gt;
For each task, select a type - builtin, http, python or script.&lt;br /&gt;
&lt;br /&gt;
For all you can configure:&lt;br /&gt;
# The maximum number of this task that can be running simultaneously&lt;br /&gt;
# The maximum number of times this task can be run for a given Kodi session&lt;br /&gt;
# A refractory period after a task is run where it won&#039;t be re-run&lt;br /&gt;
&lt;br /&gt;
For different types, there may be additional parameters to configure:&lt;br /&gt;
&lt;br /&gt;
* For scripts:&lt;br /&gt;
*# Whether the script requires the shell to run. In the majority of cases this is NOT needed. The addon will use bash on *nix or sh on Android for any .sh files.&lt;br /&gt;
*# Also, whether the program should wait for the task to complete (useful to wait during testing if the outside script prints to stdout which will be displayed).&lt;br /&gt;
*# Under some circumstances such as launching a daemon-like program, it may be desired NOT to wait for completion.&lt;br /&gt;
*# NOTE: The script file line is displayed twice: the first opens a file picker dialog. The second will allow you to edit the line or you can enter text directly. This allows you to use standard naming short cuts (i.e ~/.) or otherwise edit the way the command is sent to the interpreter instead of being committed to only picking a file.&lt;br /&gt;
&lt;br /&gt;
* For python:&lt;br /&gt;
*# Execute the python file directly OR&lt;br /&gt;
*# Import the file as a module and call whatever is designated within as &#039;run&#039; - arguments will be passed as run(args)&lt;br /&gt;
&lt;br /&gt;
* For http optionally a username and password can be provided for Basic Auth only.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note the task number as that is how it will be referred to on the next settings page.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Events ====&lt;br /&gt;
[[File:Kodi-callbacks-settings2-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
You can configure up to 10 events and have each use a different task or reuse the same task.&lt;br /&gt;
&lt;br /&gt;
Click on &#039;Choose&#039;. Your choice will appear on the following line after choosing. This was needed to make this work with other languages.&lt;br /&gt;
&lt;br /&gt;
For each event, select an event type. There are currently 29 different events.&lt;br /&gt;
&lt;br /&gt;
For some events, additional information is required:&lt;br /&gt;
&lt;br /&gt;
# For JSON notification events, the sender, method and data are required.&lt;br /&gt;
# For Window Open and Close events, the window id is needed (see: [[Window_IDs|Kodi Window Ids]]).&lt;br /&gt;
# For on Idle events, the idle time in seconds (note that idle is when there is no user interaction and no media is playing).&lt;br /&gt;
# For on Resume after Idle events, the idle time in seconds. This event will fire only after there is user activity after the defined idle time.&lt;br /&gt;
## All of the timers for on Idle and on Resume After Idle events are completely independent of one another and multiple definitions of idle time is supported.&lt;br /&gt;
## For example setting an on Idle event to dim your lights after 600 seconds and turn them off after 1200 seconds.&lt;br /&gt;
## Using on Resume After Idle, one could also set an event to turn them back on with user activity after 601 seconds, if desired.&lt;br /&gt;
# For detecting when a portion of a string is written to the log onLogSimple and and onLogRegex require &#039;matchIf&#039; strings.&lt;br /&gt;
## A simple match detects a case-sensitive substring in an individual log line, while a regex match matches whatever you configure it to on a line.&lt;br /&gt;
## Log strings can also be rejected if a different portion matches &#039;rejectIf&#039;.&lt;br /&gt;
# For File System Change events, the folder to be monitored, the file or folder patterns to monitor (ie. *.txt, *.*), the patterns to reject, whether to monitor folder changes and whether or not to monitor subfolders (recursive)&lt;br /&gt;
## For multiple patterns, separate them with a comma without spaces (i.e. &amp;quot;*.mkv,*.mp4,*.mov&amp;quot;)&lt;br /&gt;
## Similar to Script Tasks, there are two lines on the settings page for the folder. The first is a standard folder picker and the second is a free text field. This allows one to edit or type the folder directly. The free text line will allow translation of Kodi&#039;s special directories (i.e. special://) as well as OS specific substitutions such as &#039;~/.&#039; or %appdata%.&lt;br /&gt;
## In many cases monitoring folder changes is not desirable as it may create two events for each change (i.e. adding a file causes a fileAdded event AND a folderChange event).&lt;br /&gt;
## Note that on OSX, this publisher will use a low-performing, resource intensive polling routine. If this presents an issue and you are adept, install watchdog via &#039;pip&#039; and then go to your site-packages directory and copy over _fsevents.so and _watchdog_fsevents.so to the resources/lib directory.&lt;br /&gt;
# There is a separate File System Change at Startup event&lt;br /&gt;
## This takes a snapshot of any monitored folders during a normal Kodi shutdown and saves it in the addon_data folder.&lt;br /&gt;
## The snapshot is reloaded at startup and compared to a new snapshot to detect changes, using patterns as above.&lt;br /&gt;
## If any changes are detected, a single event is fired. The user can obtain the list of changes via argument substitution, if desired.&lt;br /&gt;
&lt;br /&gt;
===== Argument variable substitution =====&lt;br /&gt;
&lt;br /&gt;
A variable substituted argument string can then optionally be provided to pass additional information to your task.&lt;br /&gt;
&lt;br /&gt;
The variables that can be passed are dependent on the event and are shown on the settings page.&lt;br /&gt;
&lt;br /&gt;
Only the variables shown will be searched for and substituted.&lt;br /&gt;
&lt;br /&gt;
To ensure that literal percent signs are passed correctly, use &#039;%%&#039;.&lt;br /&gt;
&lt;br /&gt;
Because of the way arguments are passed to script files and python files, they are usually split where spaces or commas occur.&lt;br /&gt;
&lt;br /&gt;
If you need to ensure that a space is not split, use %_ (percent underscore) and for a comma, use %__ (percent underscore underscore).&lt;br /&gt;
&lt;br /&gt;
Spaces can also cause problems when they appear in the substituted variables.&lt;br /&gt;
&lt;br /&gt;
Depending on how your file processes arguments, consider placing double-quotes around variables that may contains spaces such as titles, filenames and loglines.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; If you wish to use the On Shutdown event to run a script &#039;&#039;after&#039;&#039; Kodi exits, one would use a task script which does not wait and pass out the pid (%pi) to the script. The script can then be configured to wait until the pid is no longer running and then execute the desired code. Look in the resources/lib/helpers folder for onQuit.bat and onQuit.sh for example code using this technique.&lt;br /&gt;
&lt;br /&gt;
===== Testing =====&lt;br /&gt;
&lt;br /&gt;
A fully configured event can be tested from the Event Settings Page.&lt;br /&gt;
&lt;br /&gt;
First click OK to cause any changes made to be written to the user settings file.&lt;br /&gt;
&lt;br /&gt;
Then re-enter Settings and navigate back to the event to be tested and click &amp;quot;Test command&#039;.&lt;br /&gt;
&lt;br /&gt;
First some simple validation tests will be run and if they fail, this will be reported back to the user on the screen.&lt;br /&gt;
&lt;br /&gt;
Then an attempt will be made to run the task with simulated runtime arguments (i.e. the filename, title, etc will be simulated).&lt;br /&gt;
&lt;br /&gt;
NOTE: &#039;&#039;&#039;The test will, in most circumstances, wait for the task to &#039;return&#039;. So if the task launches a program, no further information will be provided until that program ends.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Exceptions or any returned text will then be displayed.&lt;br /&gt;
&lt;br /&gt;
===== List of events =====&lt;br /&gt;
&lt;br /&gt;
Events are monitored by different &#039;&#039;publishers&#039;&#039;. The events are &#039;&#039;published&#039;&#039; as &#039;&#039;topics&#039;&#039;. Tasks then &#039;&#039;subscribe&#039;&#039; to specific topics.&lt;br /&gt;
For performance reasons, true decoupling was not achieved in this &#039;&#039;Publish/Subscribe&#039;&#039; pattern, in that only subscribed window open and close events and log matching events are published.&lt;br /&gt;
Publishers are only started if there is a subscription to one of the topics it publishes.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Event listing&lt;br /&gt;
! Player Publisher !! Monitor Publisher !! Loop Publisher !! Log Publisher !! Main Thread || Watchdog || Schedule&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackStarted || onCleanStarted || onStereoModeChange || onLogSimple || onStartup || onFileSystemChange || onDailyAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackEnded || onCleanFinished || onProfileChange || onLogRegex || onShutdown|| onFileSystemChangeAtStartup || onIntervalAlarm&lt;br /&gt;
|-&lt;br /&gt;
| onPlayBackPaused || onDPMSActivated || onWindowOpen ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackResumed || onDMPSDeactivated || onWindowClose ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeek || onNotification || onIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSeekChapter || onScanStarted || onResumeAfterIdle ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onPlayBackSpeedChanged || onScanFinished ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
| onQueueNextItem || onScreensaverActivated ||  ||  || || || &lt;br /&gt;
|-&lt;br /&gt;
&lt;br /&gt;
|  || onScreensaverDeactivated ||  ||  || || || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - General ====&lt;br /&gt;
[[File:Kodi-callbacks-settings3-1.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
The addon can optionally show a brief notification each time a task is run.&lt;br /&gt;
&lt;br /&gt;
Polling frequencies can be configured. If you have a low powered system and performance suffers causing video stuttering, consider increasing the times.&lt;br /&gt;
&lt;br /&gt;
The Loop Frequency is for events such as onIdle, onWindow open or close, profile changes and stereomode changes.&lt;br /&gt;
&lt;br /&gt;
The Log frequency is for the log checker.&lt;br /&gt;
&lt;br /&gt;
The Task frequency is for the main task dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An option is provided to elevate all routine messages to the normal log, instead of the debug log.&lt;br /&gt;
&lt;br /&gt;
A request has been made by the Kodi developers that addons avoid writing to the normal log and will be the default in Krypton and beyond.&lt;br /&gt;
&lt;br /&gt;
This setting allows you to selectively elevate messages to the normal (non-debug) log for troubleshooting and then turn it back off once fixed.&lt;br /&gt;
&lt;br /&gt;
This avoids having the user turn on the full debug mode with its OSD.&lt;br /&gt;
&lt;br /&gt;
You can click to regenerate the addon&#039;s settings.xml file. &amp;lt;u&amp;gt;This is only needed if you have created your own custom task&amp;lt;/u&amp;gt; and placed it in the resources/lib/tasks folder. This will read in whatever settings you need so that they appear on the settings pages.&lt;br /&gt;
&lt;br /&gt;
You can force the addon to log all of it&#039;s settings to kodi.log. PLEASE do this if you are uploading a log to ask for help troubleshooting.&lt;br /&gt;
&lt;br /&gt;
Last, you can run a test to ensure that tasks are working properly on your system. The results will be found in the log. You may see the debug OSD come on briefly and the system mute toggle on and off. The results may be separated in the log so look through carefully. This has been tested to work on Windows, OSX, Linux Mint and Android. There may be an issue detecting a successful builtin test on Jarvis. This will be corrected soon. On Android, python imports cannot be correctly tested, but the method works and has been tested directly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Settings - Update ====&lt;br /&gt;
[[File:Kodi-callbacks-settings4.PNG|800px|frameless|right]]&lt;br /&gt;
&lt;br /&gt;
Before any update via this page, the current installation is backed up to the addon_data folder for this addon under the sub-directory backup.&lt;br /&gt;
&lt;br /&gt;
The last five backups are kept.&lt;br /&gt;
&lt;br /&gt;
# The first line shows the branch name for the current installation. This corresponds to the available branch names on GitHub. If you install directly via the addon settings page or copy over, this may be inaccurate.&lt;br /&gt;
# Repository branch name for downloads from GitHub. When the addon runs it retrieves this info directly from GitHub. This activity triggers a warning in the log because it utilizes urlib3 via the requests module. Don&#039;t worry about the warning.&lt;br /&gt;
# You can choose to have the addon download from GitHub when updates are available and install them. An update is triggered when the version number is bumped in addon.xml. Don&#039;t worry, not every commit will be downloaded.&lt;br /&gt;
# You can allow the install to take place silently.&lt;br /&gt;
# You can manually trigger a check on GitHub and then optionally install the most recent even if the version is the same.&lt;br /&gt;
# You can also update from a manually downloaded zip file. This renames the folder name, removing the branch name so that you don&#039;t need to do it manually.&lt;br /&gt;
# You can also reinstall from one of the automatic backups.&lt;br /&gt;
&lt;br /&gt;
* Note: These routines have some advantages over installing from the main addons page built into Kodi. They automatically rename the directory. They will leave any files that you have added into the directory. Only newer files will be copied over via a timestamping mechanism in most circumstances.&lt;br /&gt;
&lt;br /&gt;
* Note: I have occasionally gotten error downloading from GitHub. If you see an error notification, please just try again. This has always worked for me as long as I have an internet connection.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Create your own custom task&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you want to do this?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have some code that does something useful and would like to make it available to others.&lt;br /&gt;
&lt;br /&gt;
Specifically if your code is written in python and others would need to give it information via the settings page.&lt;br /&gt;
&lt;br /&gt;
=== First steps ===&lt;br /&gt;
&lt;br /&gt;
Take a look at the current tasks in the resources/lib/tasks folder and the [https://github.com/KenV99/service.kodi.callbacks/blob/master/resources/lib/taskExample.py resources/lib/taskExample] file which is better documented (had to be placed here to avoid it&#039;s auto-discovery).&lt;br /&gt;
&lt;br /&gt;
Each imports a few standard needed things and then defines a class that subclasses resources.lib.taskABC.AbstractTask.&lt;br /&gt;
&lt;br /&gt;
This abstract base class provides needed functionality to work with the rest of the code.&lt;br /&gt;
&lt;br /&gt;
Note that this is itself a subclass of threading.Thread.&lt;br /&gt;
&lt;br /&gt;
=== Class definition ===&lt;br /&gt;
&lt;br /&gt;
At the class level, you need to define a &#039;tasktype&#039;. Make it unique so that it doesn&#039;t conflict but descriptive.&lt;br /&gt;
&lt;br /&gt;
Also at the class level, designate any variables that users would need to provide.&lt;br /&gt;
&lt;br /&gt;
Each requires an &#039;id&#039; that you will use to refer to it later in your code.&lt;br /&gt;
&lt;br /&gt;
Then information in settings is used to format the way it should look on the settings page.&lt;br /&gt;
&lt;br /&gt;
Refer to the Kodi wiki for the different &#039;types&#039; of settings.&lt;br /&gt;
&lt;br /&gt;
=== Class methods ===&lt;br /&gt;
&lt;br /&gt;
Then define your __init__ and call the super.&lt;br /&gt;
&lt;br /&gt;
Next you need to create a staticmethod for validate(). The user input info will be passed in as a dict with the &#039;id&#039; above as the key.&lt;br /&gt;
Return True if the input is valid, False if it&#039;s not.&lt;br /&gt;
&lt;br /&gt;
Lastly, define run(). This is the code that will be run when the event occurs.&lt;br /&gt;
&lt;br /&gt;
The reformatted variable substituted user args can be accessed via self.runtimeargs. This is provided as a list. Rejoin as necessary or overload self.processUserargs.&lt;br /&gt;
&lt;br /&gt;
The original task variables are a dict keyed for &#039;id&#039; as above (self.taskKwargs).&lt;br /&gt;
&lt;br /&gt;
Try not to raise exceptions in your code. Assemble return information or errors in a &#039;msg&#039; string and set err=True if an error occurred.&lt;br /&gt;
&lt;br /&gt;
The last thing the run code block should do is call self.threadReturn(err, msg).&lt;br /&gt;
&lt;br /&gt;
Once your custom task is placed in the proper folder, the settings.xml file for the addon needs to be regenerated via the third settings page (see above).&lt;br /&gt;
&lt;br /&gt;
Post questions on the forum. Better to put them in public and not message me directly so that others can read and learn and so I don&#039;t answer the same question privately over and over.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;Notes&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The log checking events consume the most resources and regex checks utilize more than simple checks.&lt;br /&gt;
&lt;br /&gt;
The watchdog file system watcher may also consume a lot of resources, depending on the system.&lt;br /&gt;
&lt;br /&gt;
The loop checking items consume the next most (onStereoModeChange, onProfileChange, onWindow Open or Close and onIdle/afterIdle).&lt;br /&gt;
&lt;br /&gt;
Each publisher is only started if there is a task configured that utilizes an event that it generates.&lt;br /&gt;
&lt;br /&gt;
== &#039;&#039;&#039;FAQs&#039;&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I need to a respond to an event that isn&#039;t listed as an event. Can you make it so that I can?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Most likely, no. Pretty much everything that can be detected is already there.&lt;br /&gt;
&lt;br /&gt;
A number of users have requested to launch a task when another addon/plugin launches. The only way to do that is for you to hack into their plugin and insert code to write something to the log which you then can detect via the log checker. There is an undocumented function using xbmcvfs that can list running addons, however, his doesn&#039;t work for plugins, only script and service addons. Plugins run in a &#039;detached&#039; state and often each page click causes the plugin script to run again so detecting each run is often not exactly what one may desire.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;I am having an issues, how can I get help?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The best place to get script help is in the KODI forum thread here: http://forum.kodi.tv/showthread.php?tid=256170&lt;br /&gt;
&lt;br /&gt;
If you believe that things are not working as expected, please also UPLOAD A COPY OF &#039;kodi.log&#039; TO: [http://xbmclogs.com/ XBMCLogs] or [http://pastebin.com/ pastebin] AND INCLUDE A LINK TO THE LOG IN YOUR POST! ALSO: from the &#039;General&#039; Settings page, click to write your settings to the log. This is incredibly helpful for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
I do not have a magic crystal ball. The program does not report back to me directly with your issue. No log link usually means no help can be provided.&lt;br /&gt;
&lt;br /&gt;
The forum moderators frown upon posting your log directly in the forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Add-ons not in the Kodi.tv repo]]&lt;/div&gt;</summary>
		<author><name>KenV99</name></author>
	</entry>
</feed>