Prevent screen turning off when watching video in XBMC [closed]
In 12.04, the screen never went to sleep while watching videos in XBMC. However after upgrading to 12.10 and changing no settings, it does.
Is there any way I can prevent the screen automatically turning off while playing a video in XBMC, without actually disabling the screen from turning off at other times?
Ideally, is there a XBMC specific setting for this? Was this a feature of XBMC that is now somehow broken in 12.10 or has this changed due to some other non-XBMC change within Ubuntu?
Solution 1:
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 calledxbmc.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:
Right-click on the file you just saved >> Select Properties >> In the Permission tab, put the Check mark on Execute.
-
Execute this script automatically on every startup:
We can do this with the help of Startup Applications. Open your Dash by pressing Enter and query for
Startup Applications
>> In Startup Applications Window, click on Add >> Then, in the dialog that pops up, fill the information:Name: optional, whatever you want to name this.
Command: path to the file where you saved it.
Comment: optional, if you wish to add some.
Restart your system and enjoy your movies with XBMC.
How to use it with other Applications
This was an example for XBMC (Process name xbmc.bin
). However, it can also be used for any other process of your choice by just replacing xbmc.bin
in the Script mentioned in Step-2 with the name of the process you wish. Find the following lines in the above script:
while true; do
if [[ $(pidof xbmc.bin | wc -w) -gt 0 ]]; then
while [[ $(pidof xbmc.bin | wc -w) -gt 0 ]]; do
And replace xbmc.bin
in both lines 2 and 3 with the process name of your choice.
How to find the process name
-
With GUI (GNOME):
We can use
System Monitor
to find the name of the process. Press Super to open Dash and query for "System Monitor" to launch it. In the Processes Tab, we can find the Process Name as the first column. -
With Terminal:
We can run
top
to list all the running processes. The last column calledCommand
gives us the name of the Process (however it is limited to first 15 characters).
Here we can see that Firefox is just named as firefox
. So, if we want this behavior when Firefox is running; we would replace xbmc.bin
in the script with firefox
and everything else would work just fine.
Acknowledgement: I had found the script here. However, I have made necessary modifications to make it compact and satisfy the demands of the question.
Solution 2:
A very simple solution is caffeine. Caffeine is a 'status bar application able to temporarily prevent the activation of both the screensaver and the "sleep" powersaving mode.'
Enabling it is as easy as clicking the status bar indicator, but you can also set it up such that it automatically disables the screensaver when you start xbmc. See the screenshot below
If you're using Gnome you can install the caffeine gnome extension. If not, for Ubuntu up to 15.04 (vivid) you can install caffeine from the launchpad ppa:
sudo add-apt-repository ppa:caffeine-developers/ppa
sudo apt-get update
sudo apt-get install caffeine
from 15.10 onwards you can install without ppa
sudo apt install caffeine
Enjoy!