Created
June 27, 2021 09:28
-
-
Save tyjak/3045abbf25bef7742047835e6aaa4788 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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