Script directory and additional Main Menu action

Hello,

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!

Hi

  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 192.168.0.200:9982
tcp        0      0 192.168.0.202:36456     192.168.0.200:9982      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 wake.py
#!/usr/bin/python
import xbmc
#sudo etherwake
sudo connmanctl enable ethernet
osmc@osmc:~/.kodi/userdata$ python wake.py
  File "wake.py", line 4
    sudo connmanctl enable ethernet
                  ^
SyntaxError: invalid syntax

Hi Try:

#!/usr/bin/python
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: Disabling addon by command

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 test.py
Traceback (most recent call last):
  File "test.py", line 3, in <module>
    import xbmc
ImportError: No module named xbmc

Hi,

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

~/.kodi/userdata/keymaps/keyboard.xml:
<keyboard>                                                                  
      <F11>XBMC.RunScript(special://home/test.py)</F11>                      
      <F12>XBMC.RunScript(special://home/test.py)</F12>    
</keyboard>

Thanks Tom.

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

<keyboard>                                                                  
      <F11>RunScript(/home/osmc/test.py)</F11>                      
      <F12>RunScript(/home/osmc/test.py)</F12>    
</keyboard>
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?