Skip to content

Instantly share code, notes, and snippets.

@tyjak
Created June 27, 2021 09:28
Show Gist options
  • Save tyjak/3045abbf25bef7742047835e6aaa4788 to your computer and use it in GitHub Desktop.
Save tyjak/3045abbf25bef7742047835e6aaa4788 to your computer and use it in GitHub Desktop.
#!/bin/bash
# source: https://flx.ai/2019/bose-qc35ii-linux
# GistID: 3045abbf25bef7742047835e6aaa4788
actions="toggle|prev|next|forw|back"
# Check for correct usage
if [[ $# -ne 1 || ! "$1" =~ ^($actions)$ ]]; then
echo "Usage: "
echo "${0##*/} [${actions[*]}]"
exit 1
fi
# Get focused process' name
pid=$(xdotool getactivewindow getwindowpid)
process=$(ps -p $pid -o comm=)
case $process in
# Control mpv if focused
mpv)
case $1 in
toggle)
xdotool key space
;;
prev)
xdotool key less
;;
next)
xdotool key greater
;;
forw)
xdotool click 4
;;
back)
xdotool click 5
;;
esac
notify-send "; $1"
;;
# Control mpd per default
*)
case $1 in
toggle)
mpc toggle
;;
prev)
mpc prev
;;
next)
mpc next
;;
forw)
mpc seek +1
;;
back)
mpc seek -1
;;
esac
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment