Skip to content

Instantly share code, notes, and snippets.

@nico202
Forked from exic/player-control
Last active August 1, 2016 10:04
Show Gist options
  • Save nico202/6fe051af59e336c23be2cfb9a51074f1 to your computer and use it in GitHub Desktop.
Save nico202/6fe051af59e336c23be2cfb9a51074f1 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.Prev
elif [ "$@" = "stop" ]; then
$RC.Stop
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment