Autoexec Service

From Official Kodi Wiki
Revision as of 20:47, 15 September 2020 by Ronie (talk | contribs) (Enable your addon in kodi)
Jump to: navigation, search

1 Automatically execute code when Kodi starts up.

If you wish to run some code automatically when Kodi starts, you can do so by creating a service add-on.

(This replaces the old way of adding a file in the userdata folder, this is deprecated.)

1.1 Create a folder for your autoexec add-on

Navigate to the addons folder in the Kodi Data Folder
Create a 'service.autoexec' folder in the addons folder.

1.2 Add an file

Move your existing file to this folder, or if you don't have one yet, create it and check out the code examples below.

1.3 Add an addon.xml file

Create an addon.xml file in this folder and copy and paste the following code to it:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="service.autoexec" name="Autoexec Service" version="1.0.0" provider-name="your username">
		<import addon="xbmc.python" version="3.0.0"/>
	<extension point="xbmc.service" library="">
	<extension point="xbmc.addon.metadata">
		<summary lang="en_GB">Automatically run python code when Kodi starts.</summary>
		<description lang="en_GB">The Autoexec Service will automatically be run on Kodi startup.</description>
		<license>GNU GENERAL PUBLIC LICENSE Version 2</license>

1.4 Enable your addon in kodi

Navigate to the autoexec add-on in the addonbrowser and enable it:
Settings > Add-ons > My add-ons > Services > Autoexec Service

2 Examples

2.1 Simple Examples

Here is an example that starts your favourite addon:

import xbmc

And this example takes you to the movie overview:

import xbmc

2.2 Example using profiles

import xbmc
if xbmc.getInfoLabel('System.ProfileName') == 'Master user':
elif xbmc.getInfoLabel('System.ProfileName') == 'your username':

3 References

Built-in scripting#Using Built-in Functions from python

List of built-in functions