vincentbernat.i3wm-configur.../bin/rofi-mediaplayer

62 lines
2 KiB
Text
Raw Normal View History

#!/bin/bash
2021-07-20 22:27:49 +02:00
# Media player menu with rofi
if [ -z "${ROFI_OUTSIDE}" ]; then
export mediaplayer=$1
exec rofi -show-icons -no-custom -modi m:$0 -show m \
-kb-select-1 Super+z \
-kb-select-2 Super+x \
-kb-select-3 Super+c \
-kb-select-4 Super+v \
-kb-select-5 Super+b \
-kb-select-6 Super+m \
-kb-select-7 Super+s
fi
case $ROFI_RETV in
0)
# Prompt
printf "\00prompt\x1fmedia player\n"
printf "\00message\x1f$...\n"
# Available actions
i=0
while read icon description
do
i=$((i+1))
printf "$description\00icon\x1f$icon\x1finfo\x1f$i\n"
done <<EOF
go-previous Previous track
media-playback-start Play
media-playback-pause Pause
media-playback-stop Stop
go-next Next track
multimedia-volume-control Open mixer panel
com.spotify.Client Open ${mediaplayer^}
EOF
# Player status
status=$(playerctl -p $mediaplayer status)
case $status in
Playing|Paused)
title="$(playerctl -p $mediaplayer metadata xesam:title)"
artist="$(playerctl -p $mediaplayer metadata xesam:artist)"
status="$status <span weight='light'><i>${title} (${artist})</i></span>"
;;
esac
printf "\00message\x1f${status}\n"
;;
1)
case $ROFI_INFO in
1) xdotool key --clearmodifiers XF86AudioPrev ;;
2) xdotool key --clearmodifiers XF86AudioPlay ;;
3) xdotool key --clearmodifiers XF86AudioPause ;;
4) xdotool key --clearmodifiers XF86AudioStop ;;
5) xdotool key --clearmodifiers XF86AudioNext ;;
6) i3-msg '[class="Pavucontrol"] focus' || i3-msg exec exec pavucontrol ;;
7) i3-msg '[class="'${mediaplayer^}'"] focus' || i3-msg exec exec spotify ;;
esac >&2
;;
2021-07-20 22:27:49 +02:00
esac