I have conceived a soft - shutdown method implemented by Bluetooth. Specifically, the power key of the Bluetooth remote control triggers a script. The script executes the systemctl stop kodi and systemctl start kodi commands according to whether kodi is in the running or dead state. Because systemctl stop kodi will trigger the linked shutdown of CEC, it will be helpful to some extent for machines that cannot be shut down or woken up. Can anyone help me implement it? im a newbee for coding.
til now i use ai coding a udev rules below
ACTION=="press", SUBSCRIBE=="input/event5", ATTRS{name}=="SKYWORTH_0170", ATTRS{phys}=="04:7f:0e:52:46:55", KEYCODE=="70066", RUN+="/flash/custom_power_script.sh"
and a sh below
status_info=$(systemctl status kodi)
active_status=$(echo "$status_info" | grep -oP 'Active: \K.*?(?=;)' | awk '{print $1}')
echo $active_status
if [ "$active_status" = "active (running)" ]; then
systemctl stop kodi
else
systemctl start kodi
fi
but cannot work