Skip to content

Instantly share code, notes, and snippets.

@laclaro
Created June 20, 2018 19:26
Show Gist options
  • Save laclaro/7f45c94ce91edcf38bc1210770ffa316 to your computer and use it in GitHub Desktop.
Save laclaro/7f45c94ce91edcf38bc1210770ffa316 to your computer and use it in GitHub Desktop.
bash script to detect if kodi is idle
#!/bin/bash
# bash script to detect if kodi is idle. Returns 1 if idle and 0 if kodi was still active recently.
# kodi path
kodi_webpath='http://localhost:8080/jsonrpc'
if [ -f /etc/autosuspend.conf ]; then
idle_time=$(awk -F'=' '/idle_time/{print $2}' /etc/autosuspend.conf \
| sed -e 's/^[ \t]*//')
else
idle_time=900
fi
# https://discourse.osmc.tv/t/restarting-kodi-on-keyboard-input/8381
IsIdle=$(curl -s -X POST -H 'Content-type: application/json' -d '{"jsonrpc": "2.0", "method": "XBMC.GetInfoBooleans", "params": { "booleans": ["System.IdleTime('$idle_time') "] }, "id": 1}' $kodi_webpath)
if [[ "$IsIdle" =~ true || "$IsIdle" =~ error ]]; then
# system idle or could not requested
echo "kodiIsIdle.sh: idle for at least $idle_time seconds"
exit 1
else
# system not idle
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment