How to create a KODI entry to run a script?

So you don’t see this entry?

Anyway most of your addons Youtube, TED Talks, Nasa,… have a Kodi 19 version so you just need to update and enable them

Of course I tried that before posting…
All of these updates fail with the same message about not being compatible with the new version of Kodi.
It also sometimes shows the message (in this case from YouTube):
“… xbmc.python version 2.14.0 could not be satisfied”
(It is hard to write down because the text scrolls inside a small text box and then disappears…)
This is what I have now:

$ python3 --version
Python 3.7.3
$ python --version
Python 2.7.16

So I tried

sudo apt upgrade python2
....
python2 is already the newest version (2.7.16-1).

HI,

This is a kodi issue, it can’t be fixed externally. Please try updating the kodi repo. You can check for an update in the same way as you do with other addons.

Thanks Tom.

Why go through all this trouble of sticking it in a menu instead of just triggering with a key?

<keymap>
	<Home>
		<keyboard>
			<play_pause>RunScript(/home/osmc/video-update.sh)</play_pause>
		</keyboard>
	</Home>
</keymap>

Well I am using the TV remote as the control and there are limited number of keys that get passed. Using the play key seems not to be the best choice either because I actually do want to start playing the video with a key…
Or do you mean that I can do this if the focus on screen is not a video file?
And at that time I do not have to bother with python?
Could I place this into advancedsettings.xml in addition to what I already have there?

<keymap>
  <FullscreenVideo>
    <keyboard>
      <key id="251">Seek(-180)</key>
      <key id="252">Seek(-30)</key>
      <key id="253">Seek(30)</key>
      <key id="254">Seek(180)</key>
    </keyboard>
  </FullscreenVideo>
  <Home>
    <keyboard>
      <play_pause>RunScript(/home/osmc/bin/getstreamlist)</play_pause>
    </keyboard>
  </Home>
</keymap>

BTW, if I edit advancedsettings.xml, how do I make it take effect? Do I have to reboot the osmc box or is there a simpler way?

Wrong place, keymappings go into userdata/keymaps/ see
https://kodi.wiki/view/Keymap#Defaults

Also very good to read for changing keymaps (even so title is for long press)

For changes to most files it is recommended to first stop Kodi and start afterwards.
sudo systemctl stop mediacenter
sudo systemctl start mediacenter

1 Like

Thanks,
now I have done this:

  • Edited the existing file inside the keymaps dir named lgtv.xml so it contains this:
<keymap>
  <FullscreenVideo><keyboard>
    <key id="251">Seek(-180)</key>
    <key id="252">Seek(-30)</key>
    <key id="253">Seek(30)</key>
    <key id="254">Seek(180)</key>
  </keyboard></FullscreenVideo>
  <Home>
    <keyboard>
      <key id="234">RunScript(/home/osmc/bin/getstreamlist)</play_pause>
    </keyboard>
  </Home>
</keymap>
  • Executed the following two commands:
sudo systemctl stop mediacenter
sudo systemctl start mediacenter
  • In KODI I navigated to the main menu and pressed the play button
  • Then I navigated to the streams subdirectory to check the contents and it had not changed, still contains the wrong data.

So I assume that the script is not actually executed when I hit play…
The script itself looks like this:

#!/bin/bash
# Download strm files for all recent videos
workdir="/home/osmc/temp"
streamdir="/mnt/media/USA/streams/"
streamfile="streamlist.tgz"
streamurl="https://mysecreturl.com/streams"

if [ "$1" == "R" ]
then
  eval "rm  ${streamdir}/*.strm"
fi

eval "cd $workdir"
eval "rm ${streamfile}"
eval "wget ${streamurl}/${streamfile}"
eval "tar -xvf ${streamfile} -C $streamdir"

If I run the script manually from within a PuTTY session to the RPi it updates the directory correctly.
And Kodi immediately responds by showing the new content in the directory.

I have now put the keymap data in both advancedsettings.xml and the keymaps/lgtv.xml file but nothing changes, no action from the play key when I am on the main menu (which I assume is the HOME position).

PS: The codes used in the keymapping have been found using the keymap editor earlier. DS

RunScript runs python scripts, so you would need to follow @Jahey’s advice from post 6.

1 Like

Apparently this cannot work since a shellscript will not be run by Kodi, it must be a python program according to @ooZee.
:frowning_face:

Try
<play_pause>System.Exec(/home/osmc/video-update.sh)</play_pause>

I switched to System.Exec but it did not change the behaviour…

I discovered a typo here:

<key id="234">RunScript(/home/osmc/bin/getstreamlist)</play_pause>

should be:

<key id="234">RunScript(/home/osmc/bin/getstreamlist)</key>

With this corrected the call works fine! :smiley:

Thanks a bunch!

1 Like

THANK YOU!
This was the good solution, only I messed up by entering into the wrong file and then when switching to the play button using the CEC remote numeric code I failed to change the tag end so the xml got corrupted.
Now working fine!
:smile: :smiling_face_with_three_hearts:

1 Like

As a final question:
Is there a way to feed back to the user that the script has executed?
Like showing a brief message on screen somewhere?
I.e. something that can be done inside the script file itself?

kodi-send --action="Notification(header,message[,time,image])"

1 Like

In case the formatting is confusing…

kodi-send -a "Notification(Updating Libraries,,5000)"

As for the earlier question about the button to trigger I suggested the play button on the home window as the only useful thing you can do with that button on those screens (home is all the windows on the main landing page) is pause video or music playing in the background so not a huge loss since if you just hit the back button from there you are in the fullscreenvideo/visualization where the play button would be back to playback controls.

As for the Python requirement it is my understanding that this is required if you were executing through the skin but not for a keymap.

Also if you are editing a keymap there is no reason to restart Kodi for them to take effect as the following is much quicker and elegant…

kodi-send -a reloadkeymaps

Thanks,
I added this to the end of the script:

header="Streams update"
message="Done"
kodi-send --action="Notification(${header},${message})"

The files update OK and I see the message in the upper right corner.
Perfect!
Thanks again!

1 Like

This worked fine on OSMC with Kodi18 towards an LG Smart-TV and its remote.

But when I tried it on a Philips “not so smart TV” and Kodi19 (upgraded OSMC and got Kodi19) and using this in the keys.xml file it does not work:

<keymap>
  <Home>
    <keyboard>
      <play_pause">System.Exec(/home/osmc/bin/getstreamlist)</play_pause>
    </keyboard>
  </Home>
</keymap>

Nothing happens and replacing play_pause with just play does not either.
However the play button itself works fine when playing the video (when not in Home) to start and stop the video playback…
On the Philips TV system I have failed getting the CEC key code for the TV remote play button, but the Kodi name should also work, right?

What am I missing here?

EDIT:
Just to clarify: I have a cron entry to /home/osmc/bin/getstreamlist running every hour at 12 min past the hour and when this triggers the files are updated and I get the message on the Kodi screen.
So it just seems like either the key is not picked up by Kodi or System.Exec on Kodi 19 is not able to run a standard shellscript…

Look close at what you did on the Philips!!! Very close. Just a hint, but maybe the " just might be an issue :wink:

:confused:
Yes I see what you mean, it was an editing mistake when I took out the <key id="xxx">
So I edited it out to now look like this:

<keymap>
  <Home>
    <keyboard>
      <play_pause>System.Exec(/home/osmc/bin/getstreamlist)</play_pause>
    </keyboard>
  </Home>
</keymap>

And then I applied
kodi-send -a reloadkeymaps

But unfortunately nothing still happens when I hit either play or pause on the Home screen…
I also tested
<play>System.Exec(/home/osmc/bin/getstreamlist)</play>
But still no go.

Maybe I really need to restart Kodi?
(No, tested that and it did not work)

Or is Kodi19 (nonworking) different from Kodi18 (working)?

Hi,

Please enable debug logs, reproduce and upload the logs.

Thanks Tom.