Last Updated: March 07, 2016
·
395
· sakarikl

pause and resume spotify on screen lock and unlock on ubuntu

#!/bin/bash
dbus-monitor --session "type='signal',interface='com.ubuntu.Upstart0_6'" | \
(
  while true; do
    read X
    if echo $X | grep "desktop-lock" &> /dev/null; then
      dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Pause >/dev/null;
    elif echo $X | grep "desktop-unlock" &> /dev/null; then
      dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Play > /dev/null;
    fi
    sleep 1
  done
)