Wikia

Music Player Daemon Community Wiki

Watchlist Recent changes

Hack:pause-on-screensaver

#!/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
# (http://live.gnome.org/RhythmboxPlugins/ThirdParty#Screensaver_Play.2BAC8-Pause)
# 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

Pages on Music Player Daemon Community Wiki

Add a Page
543pages on
this wiki
Advertisement | Your ad here

Latest Photos

Add a Photo
114photos on this wiki
See more >

Recent Wiki Activity

See more >

Around Wikia's network

Random Wiki