How to add a custom script shortcut in KODI

Here is a guide that shows how to add a custom shortcut in KODI (i.e. to run a pre-made BASH script, such as my partition switching script).

In the screenshots below I am using the Aeon Nox skin, but the idea is the same for other skins too.

First navigate to the ‘System’ menu on the home screen:

screenshot000

Click on ‘System’ (or press <Enter> or OK) to open the ‘Settings Screen’:

screenshot001

Click on ‘Appearance’ and you will see the screen below:

screenshot002

Click on the ‘Settings’ button underneath where it says ‘Skin’ and you will see the screen below:

screenshot003

Click on ‘Setup the Aeon Nox Main Menu’ and you will see the below screen that lists all the different home screen categories:

screenshot004

In this example we will create a new category / menu item. Scroll down the left side of the page until you highlight the ‘Custom1’ menu, as below:

screenshot005

Now click on ‘Default Select Action’ and you will be presented with a list of actions that can be assigned to this menu button when clicked on. Scroll down until you find ‘Custom Item’ (it will be at the bottom of the list):

screenshot006

Click on ‘Custom Item’ and an input screen will appear – we will use this to enter the custom command. A full list of KODI commands can be found by clicking here, however the only command we need right now is the ‘System.Exec’ command, which tells KODI to run a BASH script and all we do is link to a pre-made batch file. Type in the following exactly:

System.Exec(/storage/ss/select.sh)

Now if you are using one of my builds then this will link to a BASH script I made that simply displays a message to the user asking them to click on the ‘Launch RetroPie’ button’. The contents of that BASH script is below:


#!/bin/bash

kodi-send –action=”Notification(GAMES,Select ‘Launch RetroPie’ to start gaming!,3000,/storage/ss/icon.png)”


All the script above does is tell KODI to display a notification with the header of ‘GAMES’ with text underneath stating ‘Select ‘Launch RetroPie’ to start gaming!’. The ‘3000’ is how long the notification is displayed for (3 seconds), and the /storage/ss/icon.png is a small icon file I made that shows the RetroPie logo in the notification (this is optional).

OK so back to the ‘Custom1’ KODI menu – so now you have entered the text above you should see the below screen:

screenshot007

If so then click ‘Done’ and you will be returned to the ‘Custom1’ screen but now it will show what the Default Select Action is:

screenshot008

OK so now we will set up the ‘Launch RetroPie’ submenu by clicking on ‘Manage Submenu’:

screenshot009

screenshot010

In here you can see all the different types of submenu options that the skin supports, but we are only interested in adding a custom script so click ‘Change Action’ and scroll down to find ‘Custom Item’:

screenshot011

Click ‘Custom Item’ and you will be prompted with the input screen again and same as earlier you need to link the pre-made bash script so type the below exactly:

System.Exec(/storage/ss/games.sh)

That tells KODI to run the ‘games.sh’ script when the button is clicked and that script is what changes the NOOBS partition number and reboots the Pi into the RetroPie partition (in this example). Here is the contents of that script:


#!/bin/bash

kodi-send –action=”Notification(GAMES,Launching RetroPie!,4000,/storage/.kodi/ss/icon.png)”

cd ~
mount /dev/mmcblk0p1 noobs
cp ~/.kodi/ss/autobootgames.txt ~/noobs/autoboot.txt

sleep 2

cd ~/.kodi/ss/
kodi-send –action=”PlayMedia(/storage/.kodi/ss/launch.wav)”

sleep 1

reboot


That script displays a notification with the header ‘Games’ and text of ‘Launching RetroPie!’ for 4 secconds and in the background it is mounting the NOOBS partition (/dev/mmcblk0p1) to an empty folder named ‘noobs’ (/storage/noobs/), and copying a text file named ‘autobootgames.txt’ out of the /storage/ss/ folder and into the /storage/noobs/ folder, renaming it to ‘autoboot.txt’. This text file is what tells NOOBS which partition you want to boot into and it uses a numbering system. Here is the contents of the ‘autobootgames.txt’ file

boot_partition=7

It literally just tells NOOBS to boot into partition mmcblk0p7, which is the boot partition for RetroPie. The boot partition for KODI is mmcblk0p5 so the ‘autoboot.txt’ file that I use in RetroPie to switch back to KODI reads boot_partition=5. That is, in a nutshell, how my partition switching script works, so back to the ‘games.sh’ contents above – after the autoboot text file has been copied over I get KODI to play a Space Invaders sound sample (named launch.wav), and then it waits for 1 second (to ensure the sound sample is not cut off), then reboots. On next boot it will load into RetroPie instead of KODI. 

 

Now back to the guide! You have entered the custom script command as above and it should look like this:

screenshot007

If so then press ‘Done’ and you will be returned to the following screen:

screenshot013

Now you want to click on ‘Set Label’ to give your custom shortcut a name – I call mine ‘Launch RetroPie’ which keeps in line with what my ‘Select.sh’ script tells the user to do:

screenshot014

Click ‘Done’ after you have entered the name and you will be returned to the sub-menu screen again but this time it will show the name you entered for the menu item:

screenshot015

We are now finished in here (unless you wanted to add more sub-menu items), so just click ‘Back’ to return to the ‘Custom1’ settings screen. Now you can add a custom background to the custom menu item if you want. Click on the ‘Set Item Background’ button and then you can choose the background you want to use:

screenshot016

I generally use ‘Single Image Background’ for this menu, but you can choose whatever you want. For the purpose of this guide, click ‘Set Single Image Background’ and you will see the below:

screenshot017

Click ‘Home Folder’ and navigate to the picture you want to use. Mine is stored at /storage/ss/games.jpg, as below:

screenshot018

Click on the picture you want to use and it will be stored, you will see it when returned to the ‘Custom1’ settings screen:

screenshot019

Now all that is left to do is name this new custom menu item, because ‘Custom1’ isn’t very explanatory! Click on ‘Edit Label’ and an input box will appear. Enter the name you want to use (in this example it is ‘Games’):

screenshot021

Click ‘Done’ when you have entered the name and you will see it has now updated in the settings menu:

screenshot022

Now we are all done and your custom menu item is ready to try out! Exit back to the home screen (the skin might need a moment or two to update so let it do its thing), and navigate to your new home screen menu item and look at it in awe:

screenshot023

Now test your scripts work by clicking on them and you’re done! You can now modify your BASH scripts to do different things if you want, using the link I posted further up the page. You can send sounds, images, videos etc. through at the click of a button so give it a try!

 

I hope you found this useful and it makes sense! Any questions just ask below.

All the best, Steve.