Thursday, 5 August 2010

Python: 'Inhibiting' the gnome-screensaver while watching videos

As user Styelz noted in the last blog post about this, the script with "gnome-screensaver-command -p" uses 100% CPU while running.
So I made a new script for this purpose that uses the "gnome-screensaver-command -i" call. The -i or --inhibit command argument stops/inhibits gnome screensaver and gnome power manager at the same time. Here is the full script:

#!/usr/bin/python
import subprocess

#run inhibition
ss_inhibit = subprocess.Popen(["gnome-screensaver-command", "-i", "-n",
"mplayer", "-r", "video"])

#run gmplayer
player = subprocess.Popen("gmplayer")

#wait for mplayer to exit
player.wait()

#kill the inhibition
ss_inhibit.kill()


Inhibition command is:

gnome-screensaver-command -i -n mplayer -r video


Options used here are:
-i -> inhibit the screensaver from activating.
-n mplayer -> the calling application that is inhibiting the screensaver is mplayer.
-r video -> reason for inhibiting the screensaver - video