Fandom

Music Player Daemon Community Wiki

Hack:pause-on-screensaver

525pages on
this wiki
Add New Page
Talk0 Share
#!/bin/bash

# This little dirty hack waits for D-Bus events from GNOME screensaver and
# toggles music playing on each of them. Since 2011-12-13 it checks if mpd was
# playing music and resumes it only if it was
# Inspired and influenced by "Screensaver Play/Pause" Rhythmbox plugin by Jannik
# Heller
# ([1])
# Written by Vadim "dexpl" Raskhozhev, licensed under WTFPL

_dbus_expr="type='signal',interface='org.gnome.ScreenSaver',member='ActiveChanged'"
_event_expr='^[[:space:]]*boolean\ (true|false)'
_bool_expr='*boolean'
# 1 here means that mpd was _not_ playing
_was_playing=1

play_pause() {
# if screensaver activated
    if [ $1 -eq 0 ]; then
# find if mpd plays music
        mpc | grep -q '^\[playing\]'
        _was_playing=$?
        [ "$_was_playing" -eq 0 ] && mpc pause
    else
# if screensaver deactivated
# resume only if mpd was playing when screensaver activated
        [ "$_was_playing" -eq 0 ] && mpc play
    fi
}

dbus-monitor --session "$_dbus_expr" | while read _line ; do
    if [[ "$_line" =~ $_event_expr ]]; then
        ${_line#${_bool_expr}}
        play_pause $?
    fi
done

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random Wiki