Guest - Testers are needed for the reworked CDateTime core component. See... https://forum.kodi.tv/showthread.php?tid=378981 (September 29) x
How to add a keybind that runs a script?
#1
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.
Reply
#2
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?
Reply
#3
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?
Reply
#4
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.
HP Stream Mini w/Libreelec -> HDMI -> Toshiba 37"
Intel NUC8i3BEH w/Libreelec -> HDMI -> LG OLED55C3PUA -> S/PDIF -> Sony HT-CT80
Dell Optiplex 7050 Micro w/Libreelec -> HDMI -> Yamaha RX-V467 -> HDMI -> Toshiba 47L7200U
Reply
#5
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
Reply

Logout Mark Read Team Forum Stats Members Help
How to add a keybind that runs a script?0