Skip to content

Instantly share code, notes, and snippets.

@exic
Created December 2, 2014 12:16
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save exic/1d051e3a15f61e06caf4 to your computer and use it in GitHub Desktop.
Save exic/1d051e3a15f61e06caf4 to your computer and use it in GitHub Desktop.
Control a player implementing MPRIS D-Bus Specification v2.2
#!/bin/sh
name="$1"
shift
PATHS="org.mpris.MediaPlayer2.$name /org/mpris/MediaPlayer2"
DBUS_SEND="dbus-send --type=method_call --dest=$PATHS"
RC="$DBUS_SEND org.mpris.MediaPlayer2.Player"
if [ "$@" = "prev" ]; then
$RC.Previous
elif [ "$@" = "stop" ]; then
$RC.Pause
elif [ "$@" = "toggle" ]; then
$RC.PlayPause
elif [ "$@" = "next" ]; then
$RC.Next
elif [ "$@" = "random" ]; then
current=$(mdbus2 $PATHS org.freedesktop.DBus.Properties.Get org.mpris.MediaPlayer2.Player Shuffle)
if [ "$current" = "( true)" ]; then
other=false
else
other=true
fi
$DBUS_SEND org.freedesktop.DBus.Properties.Set string:org.mpris.MediaPlayer2.Player string:Shuffle variant:boolean:$other
else
echo "Command not found for player $name: $@" 1>&2
exit 1
fi
@nmrugg
Copy link

nmrugg commented Jul 8, 2015

Note: Insert export DISPLAY=:0 at line 2 to make this work via ssh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment