Kodi Community Forum
How to add a keybind that runs a script? - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33)
+--- Forum: General Support (https://forum.kodi.tv/forumdisplay.php?fid=111)
+---- Forum: Linux (https://forum.kodi.tv/forumdisplay.php?fid=52)
+---- Thread: How to add a keybind that runs a script? (/showthread.php?tid=378158)



How to add a keybind that runs a script? - jim_p - 2024-07-11

Hello everyone.
I want to add a keybind that will run a script and pop a notification about the cpu's temperature inside kodi. For that purpose, I will use libreelec's built in "cputemp" command, but because I can not add/run it directly to a notification action, I made this tiny bash script that grabs it as a text and adds it there.
 
Code:
# cat test.sh
#!/bin/bash
t=$(/usr/bin/cputemp)
kodi-send --action=notification"($t,temp,10000)"
This is how it looks inside kodi
Image

After that, I have to add it to a keybind which will be avaiable everywhere, so I made this xml file
 
Code:
# cat test.xml
<keymap>
        <global>
                <keyboard>
                <t mod="longpress">System.Exec(/storage/test.sh)</t>
                </keyboard>
        </global>
</keymap>
I have already tested if it works by making it grab a screeshot when longpressing "t" (it runs "TakeScreenshot" instead of all that) and it works just fine. However, not only it does not work with the above command but it freezes the entire kodi and I have to ssh to it and reboot the system (single purpose laptop running libreelec). What am I doing wrong?

p.s. Due to high temperatures here, I may be afk the following days, so please excuse any delays in answering. I will do my best to reply in timely manner.


RE: How to add a keybind that runs a script? - jim_p - 2024-07-11

Major (or minor) update. The keybind works now! I deleted and redid everything just to be sure.
However, it works only when kodi is not playing something, i.e. it works on any kodi menu but not when a video is playing. Any ideas why?


RE: How to add a keybind that runs a script? - jim_p - 2024-07-12

As it seems, on video playback, "t" toggels the subtitles visibility (I knew that already) and it does not care if i longpress it or not, it still does that action.
Is there a key (a letter prefferably) which is not bound to any action?


RE: How to add a keybind that runs a script? - Jogee - 2024-07-12

Keyboard controls are noted in the Wiki - Keyboard_controls (wiki)

Note that some are Global, and some just specific to a particular section.

As an alternative, you may want to consider doing and ALT or CTRL mod with T.


RE: How to add a keybind that runs a script? - jim_p - 2024-07-15

I knew that page, I even have it in my bookmarks. I tried setting "g" (single press, not longpress) for the job which works everywhere but the pvr menu. It also froze kodi and I had to close the system from the power button. And this is where I gave up with the keybinds and made this.

Here is a script, which is run by a systemd service, which in turn runs every 5 minutes via a systemd timer. The script checks if the cpu temperature is above 75C and if it is, it just stops any playback, mentions the temperature it has reached and shutdowns the system via a kodi action. It goes without saying that the (advanced linux) who plans to use it will have to find the right device under /sys/class/hwmon and that cputemp is a command which exists as built in only in *elecs. The 1 minute delay for the start of the service is there because le's systemd was complaining that it could not start it properly.
 
Code:
# cat /storage/toohot.sh
#!/bin/bash

temp=$(cat /sys/class/hwmon/hwmon0/temp1_input)
temp_crit=75000
t=$(/usr/bin/cputemp)

if [ $temp -lt $temp_crit ] ; then
        echo "all good"
else
        echo "omg we are gonna burn"
        kodi-send --action="Notification($t!, closing in 10, 5000)"
        sleep 5
        kodi-send --action=Stop
        sleep 10
        kodi-send --action=Shutdown
fi
 
Code:
# cat /storage/.config/system.d/toohot.service
[Unit]
Description=Shutdown the system if it gets too hot
Wants=toohot.timer

[Service]
Type=oneshot
ExecStart=/storage/toohot.sh

[Install]
WantedBy=multi-user.target

Code:
# cat /storage/.config/system.d/toohot.timer
[Unit]
Description=Runs every 5 minutes
Requires=toohot.service

[Timer]
Unit=toohot.service
OnBootSec=1min
OnCalendar=*-*-* *:0/5:00

[Install]
WantedBy=timers.target
p.s. If you see anything that does not match between the files, please ask me to correct it. It's because all messages, and even the names of the files themselves, were written in greek (with english characters) and I had to translate them before posting them here. Big Grin