XBMC exposes a JSON API that allows you to query its status and remotely control it. I need the API to check if XBMC is currently playing content (manifesting itself in a running player) and if not, automatically shut down the living room pc to save energy. Fortunately, the API comes with the Player.GetActivePlayers call. As the name indicates, it returns the currently active players meaning no players no activity and thus the machine can shut down. Combining curl with a few simple python parsing returns a number for active players.
curl -s -u xbmc:xbmc -X POST -H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "method": "Player.GetActivePlayers", "id": 1}' \
http://localhost:8080/jsonrpc | \
python -c 'import json,sys;obj=json.load(sys.stdin);print len(obj["result"])'