Search code examples
bashlaunchkodi

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?


Solution

  • 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.