Script directory and additional Main Menu action


i have two questions…

  1. I want to perform a script when the system goes in suspend mode. In LibreELEC there is a sleep.d directory for such scripts. Is it in OSMC also possible to perfor a script when switching in suspend mode?

  2. It is possible to perform a shell command (or script) additional when i select a certain main menu button (select “PVR & Live TV” button -> perform default ActivateWindow(TVGuide) + shell command or script)?

Thanks in advance!


  1. See [HOWTO] Vero 4K / 4K: Performing actions programatically on Standby and Wakeup

  2. Yes, you could write a Python script and map it to be invoked. The easiest way would be with Keymap Editor

Keymap editor does not support calling any scripts. If you open that add-on it will actually destroy any that were manually created. Furthermore the use case being asked about, invoking an additional action when a main menu item is selected, is not something that can be affected with a keymap anyway. AFAIK this is something that would have to be done by customising a skin.

If someone wanted to make a custom button on their remote to perform the function they could do this manually by putting everything in an external script (you can only map a single action to a key) and keymapping to that. In the script they could use a kodi-send --action="ActivateWindow(TVGuide)" to bring up that menu along with whatever else their doing with the script.

Thanks for your replies!

The additional command or skript should only kill the process that holds the network connection to the tvheadend server. Now i have seen that this process is unfortunately the kodi process itself:

osmc@osmc:~$ sudo netstat -pn | grep
tcp        0      0      ESTABLISHED 2562/kodi.bin

What would you recommend to stop this network connection, maybe stop and start the tvheadend client addon via a command on suspend and wakeup?

I need to stop this network connection in suspend, otherwise my tvheadend server (other machine) is running all the time and can’t switch to suspend itself.

You can use connmanctl to disable the used technology (Ethernet or wifi) and re-enable afterwards.

Unfortunately i have currently no python knowledge at all but will learn the basics if it is necessary for further adjustments.

Can you tell me how i can run the connmanctl command in a phyton script?

osmc@osmc:~/.kodi/userdata$ cat
import xbmc
#sudo etherwake
sudo connmanctl enable ethernet
osmc@osmc:~/.kodi/userdata$ python
  File "", line 4
    sudo connmanctl enable ethernet
SyntaxError: invalid syntax

Hi Try:

import xbmc
import os

#sudo etherwake
os.system('sudo connmanctl enable ethernet')

Thanks Tom.

Thats works perfect - thanks!

I have now already created my wake/standby and menu scripts.

My (hopefully) last problem is that i dont know how to set these scripts as menu action. I dont find them when i adjust the menu actions in the customize menu section.

Just enter the absolute path to the scripts - did it! :slight_smile:

Everything works fine, but i have two questions to optimize:

  • how to avoid the tvheadend during i watch something
  • it is also possible to deactivate and activate the tvheadend client addon instead of deactivate and activate the network?

It should be possible. Take a look at:

Thanks for your reply.

How can i run the xbmc.executeJSONRPC command? I have tried to import xbmc like described in your howto, but get a error:

osmc@osmc:~/.kodi/userdata$ python
Traceback (most recent call last):
  File "", line 3, in <module>
    import xbmc
ImportError: No module named xbmc


It needs to called from within kodi. I would map it to a keyboard key or a remote, so for example:


Thanks Tom.

If that doesn’t work you could try this format which I have used successfully.

1 Like

xbmc.executeJSONRPC(’{“jsonrpc”:“2.0”,“method”:“Addons.SetAddonEnabled”,“id”:7,“params”:{“addonid”: “%s”,“enabled”:false}}’ % CHOICE)

The command disables the addon with id 7, correct? How can i find out which id’s are assigned to the installed addons?