TSG
TSG

Reputation: 4617

Launch script from Kodi menu

I'm running Kodi 18 and I would like to add an item to the main menu which simply launches a bash script. After much searching, there is no obvious way to edit the menu (and I don't want to change themes just for that).

I don't want to create an entire plug-in just for this either (which seemed to be the only alternative found by google).

Is this so simple that no one has posted a how to? Or is this not possible? Can someone provide advice?

Upvotes: 1

Views: 5851

Answers (2)

Daniël Sonck
Daniël Sonck

Reputation: 889

If changing themes is not a problem, you can also use the Aeon series of themes which usually allow customizing the main menu. Of course, this is only a solution if you like the look of them, but they are generally customizable.

As a quick check for skins available for Kodi 18:

  • Aeon (most versions except Tajo is a bit simple compared to others)
  • Amber
  • Unity (seems to share what I used in Aeon)
  • Rapier (a bit more limited but can still add custom actions like System.Exec)

With these skins you can edit the home menu (through various screens under Skin Settings available at the "Interface" Settings menu of Kodi). There you can pick a custom command and use System.Exec and System.ExecWait. I did have issues on Windows with Kodi 18 and commands having a space in their path, this can be fixed by making the executable available in $PATH and making sure the executable name doesn't contain spaces.

EDIT

I just realized you don't want to switch themes (I read not want to create one). For that, unfortunately the default (Estuary) skin doesn't offer customizability, however, you can edit addons/skin.estuary/xml/Home.xml. In this file, you can find this bit:

...
                    <content>
                        <item>
                            <label>$LOCALIZE[342]</label>
                            <onclick condition="Library.HasContent(movies) + Skin.HasSetting(home_no_categories_widget)">ActivateWindow(Videos,videodb://movies/,return)</onclick>
                            <onclick condition="Library.HasContent(movies) + !Skin.HasSetting(home_no_categories_widget)">ActivateWindow(Videos,videodb://movies/titles/,return)</onclick>
                            <onclick condition="!Library.HasContent(movies)">ActivateWindow(Videos,sources://video/,return)</onclick>
                            <property name="menu_id">$NUMBER[5000]</property>
                            <thumb>icons/sidemenu/movies.png</thumb>
                            <property name="id">movies</property>
                            <visible>!Skin.HasSetting(HomeMenuNoMovieButton)</visible>
                        </item>
...

Here you can change this to the following (as example):

...
                    <content>
                        <item>
                            <label>Firefox</label>
                            <onclick>System.Exec(firefox)</onclick>
                        </item>
                        <item>
                            <label>$LOCALIZE[342]</label>
                            <onclick condition="Library.HasContent(movies) + Skin.HasSetting(home_no_categories_widget)">ActivateWindow(Videos,videodb://movies/,return)</onclick>
                            <onclick condition="Library.HasContent(movies) + !Skin.HasSetting(home_no_categories_widget)">ActivateWindow(Videos,videodb://movies/titles/,return)</onclick>
                            <onclick condition="!Library.HasContent(movies)">ActivateWindow(Videos,sources://video/,return)</onclick>
                            <property name="menu_id">$NUMBER[5000]</property>
                            <thumb>icons/sidemenu/movies.png</thumb>
                            <property name="id">movies</property>
                            <visible>!Skin.HasSetting(HomeMenuNoMovieButton)</visible>
                        </item>
...

Which would place a Firefox menu item at the top of the menulist.

Kodi Estuary with custom menu item

Note, while you can edit this addon inplace, it's likely to overwrite the changes when the skin updates. Therefore it's best to copy over the folder with a new name and update addon.xml to change the id of the plugin and optionally add your name to it. This is obviously more involved, but I think it's the only way you can have it without truly changing the skin and without writing a plugin from scratch.

Upvotes: 2

adelille
adelille

Reputation: 26

This partially answer your question: instead of creating an item in the main menu, it allows creating a keyboard shortcut to your script.

Two built-in functions allows executing bash scripts:

System.Exec(exec)

Execute shell commands. The full path to the script has to be placed inside the parentheses.

System.ExecWait(exec)

Execute shell commands and freezes Kodi until shell is closed. As well as for "System.Exec(exec)", the full path to the script has to be placed inside the parentheses.

The information comes from here. I've tested the second one which works flawlesly with a bash script located in ~/.local/bin but with one limitation: you can't pass argument to the script. ~/.local/bin is in the default user $PATH (on Raspbian) which allowed me to use only the script name and not the full path.

You can call this function by creating a user keyboard shortcut file

nano ~/.kodi/userdata/keymaps/keyboard.xml

and adding into it

<keymap>
  <global>
    <keyboard>
      <a mod=shift,ctrl>System.ExecWait(script.sh)</a>
    </keyboard>
  </global>
</keymap>
  • keymap is the overall description of the file and should not be changed.
  • global refers to which window the link can be available (global is a fallback if the shortcut is not used in the current specific window)
  • keyboards refers to the keyboard shortcuts (you can add gamepad, mouse, etc.)
  • a is the key activating the shortcut, here with the modifiers shift+ctrl (that can be dropped for a single key shortcut, but beware of conflicts with existing shortcuts). Don't forget to also modify it at the end of the line.
  • script.sh is your script name (full path if not in the user $PATH) that must be executable, as goes for all shell scripts.

Upvotes: 1

Related Questions