Prevent screen turning off when watching video in XBMC
We can create a shell script which would simulate mouse movement at a specified interval (only when XBMC is running) and prevent your screen from turning off.
Follow the steps:
Install necessary tools:
We would need xdotool to do this job for us. Install it by running the following command in terminal:
sudo apt-get install xdotool
The Script:
Save the following script anywhere on your PC. You can modify sleep_period according to your needs, I have set it at 60 seconds. The script checks if there is a process called xbmc.bin running; and if it finds one, then it loops to simulate mouse movement while the process is active. Otherwise, checks for the process again after the specified interval.
#!/usr/bin/env bash
sleep_period=60s #seconds
mouse_x=0
mouse_y=0
movement_px=2
mouse_x=$(xdotool getmouselocation 2>/dev/null | sed -e 's/x://' -e 's/y//' -e 's/ screen:.*$//' -e 's/ //' | awk 'BEGIN {FS=":"} {print $1}')
mouse_y=$(xdotool getmouselocation 2>/dev/null | sed -e 's/x://' -e 's/y//' -e 's/ screen:.*$//' -e 's/ //' | awk 'BEGIN {FS=":"} {print $1}')
while true; do
if [[ $(pidof xbmc.bin | wc -w) -gt 0 ]]; then
while [[ $(pidof xbmc.bin | wc -w) -gt 0 ]]; do
xdotool mousemove $((mouse_x+${movement_px})) $((mouse_y+${movement_px}))
xdotool mousemove $((mouse_x-${movement_px})) $((mouse_y-${movement_px}))
sleep ${sleep_period}
done
else
sleep ${sleep_period}
fi
done
Make this script executable.