How do I stop xscreensaver during movies play?
You may try similar script to this one. Watch for player state through DBUS.
I lower delay to 55 sec, work better with 1min screen saver idle time.
-
Example VLC:
BTW, VLC in Ubuntu 14.04 has DBUS interface enabled by default. Where in Ubuntu 12.04 is not. Check it from:
Tools → Preferences → Advanced (or All) → Interface → Control Interfaces → D-Bus control interface. (Apply then Restart VLC)
-
Create a file
heartbeat.sh
in~/Desktop/
:#!/bin/bash while sleep 55 do if [ "$(pgrep vlc)" != "" ] then state=$(bash -c 'gdbus call --session \ --dest org.mpris.MediaPlayer2.vlc \ --object-path /org/mpris/MediaPlayer2 \ --method org.freedesktop.DBus.Properties.Get \ "org.mpris.MediaPlayer2.Player" \ "PlaybackStatus"') if [ "$state" = "(<'Playing'>,)" ] then #xscreensaver-command -deactivate xset s reset fi fi done
Open terminal Ctrl+Alt+t
-
Add run permissions:
chmod +x ~/Desktop/heartbeat.sh
-
Run script:
~/Desktop/heartbeat.sh
Try VLC player.
-
-
For Gnome MPlayer (D-Bus enabled by default), use:
"$(pgrep gnome-mplayer)"
and--dest org.mpris.MediaPlayer2.gnome-mplayer
-
For (Totem) Videos player (D-Bus plugin disabled by default),
Edit → Plugins → Check D-Bus service. (Restart totem)
Use:
"$(pgrep totem)"
and--dest org.mpris.MediaPlayer2.totem
-
This is modified with to work with any player that provide MPRIS. It gets the list dynamically (drawback, it doesn't distinguish between audio only play and video play). The best way I think is to put manually the list of players you like:
#!/bin/bash players_list=$(gdbus call --session --dest org.freedesktop.DBus \ --object-path / --method org.freedesktop.DBus.ListNames | \ awk 'BEGIN { RS=","; } /org.mpris.MediaPlayer2./ { gsub(/[\[\]()\x27]/, ""); print $1; }') while sleep 55 do for player in $players_list do state=$(gdbus call --session \ --dest $player \ --object-path /org/mpris/MediaPlayer2 \ --method org.freedesktop.DBus.Properties.Get \ "org.mpris.MediaPlayer2.Player" \ "PlaybackStatus") if [ "$state" = "(<'Playing'>,)" ] then echo $player $state send signal #xscreensaver-command -deactivate #use xset to work with all screensaver tools and avoid dimming display ... xset s reset break else echo $player $state fi done done
Debug hints:
-
Watch X idle time
watch -n1 xprintidle
or:
while sleep 1; do xprintidle; done;
-
Check if disabling screensaver works (while running this script, xscreensave should not pop up)
#!/bin/bash while sleep 55 do #xscreensaver-command -deactivate #xdg-screensaver reset xset s reset done
-
Check for DBUS list for MPRIS player interface, example with VLC running:
gdbus call --session --dest org.freedesktop.DBus \ --object-path / --method org.freedesktop.DBus.ListNames | \ awk 'BEGIN { RS=","; } /org.mpris.MediaPlayer2./ { gsub(/[\[\]()\x27]/, ""); print $1; }'
Output:
org.mpris.MediaPlayer2.vlc org.mpris.MediaPlayer2.vlc.instance3939
Or using
dbus-send
commanddbus-send --session \ --dest=org.freedesktop.DBus \ --type=method_call \ --print-reply \ /org/freedesktop/DBus \ org.freedesktop.DBus.ListNames \ | grep org.mpris.MediaPlayer2.
Output:
string "org.mpris.MediaPlayer2.vlc" string "org.mpris.MediaPlayer2.vlc.instance3939"
References:
- How to set up DBus query to get play state of VLC? original script by JB0x2D1
- MPRIS D-Bus Interface Specification
- Use
qdbusviewer
to check the correct destination name or to use other player you like.
For MPV, and mplayer, the heartbeat functionality is built in.
1) Locate your mpv configuration file. locate mpv.conf
2) Open it up. sudo nano /path/to/mpv.conf
3) Add this line at the bottom. heartbeat-cmd="/usr/bin/xscreensaver-command -deactivate > /dev/null"
4) Close, and save. Ctrl+X if using nano.
Find out where to find your mpv.conf file here (configuration is identical on Arch Linux), https://wiki.archlinux.org/index.php/Mpv#Configuration
If the environment variable XDG_CONFIG_HOME is not set, user configuration files will be read from the ~/.config/mpv directory. System-wide configuration files are read from the /etc/mpv directory.