Skip to content

Instantly share code, notes, and snippets.

@chanux
Last active September 28, 2016 10:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chanux/db01bd2c66effc7a259f to your computer and use it in GitHub Desktop.
Save chanux/db01bd2c66effc7a259f to your computer and use it in GitHub Desktop.
Multimedia keybindings that works with Spotify and mocp and contect aware
#!/usr/bin/env bash
# Make your multimedia keybindings work with both spotify and mocp.
# I prefer to have them control Spotify when it's open.
# Place this script somewhere in $PATH and bind multimedia keys/your favorite
# shortcuts accordingly. The commands are self explanatory
#
# playdog -playpause
# playdog -pause
# playdog -next
# playdog -previous
#
# How to bind keys on Ubuntu: http://wp.me/p1rVu-bC
function dbus_controls() {
case $2 in
-next)
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.${1} /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next
;;
-previous)
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.${1} /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous
;;
-pause)
dbus-send --print-reply --session --dest=org.mpris.MediaPlayer2.${1} /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Pause
;;
-playpause)
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.${1} /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause
;;
esac
}
# The order determines priority
if pgrep -c vlc; then
dbus_controls "vlc" $1;
elif pgrep -c spotify; then
dbus_controls "spotify" $1;
elif pgrep -c mocp;then
case $1 in
-next)
mocp --next
;;
-previous)
mocp --previous
;;
-playpause)
mocp --toggle-pause
;;
-pause)
mocp --pause
;;
esac
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment