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>