-
Notifications
You must be signed in to change notification settings - Fork 4
/
music
executable file
·47 lines (41 loc) · 1.57 KB
/
music
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
#----------------------------------------------------------------------------------------------------
# Requires playerctl - https://github.com/acrisci/playerctl
#----------------------------------------------------------------------------------------------------
#Exit the script if no music players running
[[ "$(playerctl status 2>&1)" = "No players found" ]] && exit 33;
# Define cursor icons
playIcon="";
pauseIcon=" ⏸️";
stopIcon=" ⏹️";
#User provided args for playerctl
ARGUMENTS="$INSTANCE";
#Mouse actions for the block
case $BLOCK_BUTTON in
1) playerctl $ARGUMENTS previous ;;
2) playerctl $ARGUMENTS play-pause ;;
3) playerctl $ARGUMENTS next ;;
4) playerctl $ARGUMENTS position 5+ ;;
5) playerctl $ARGUMENTS position 5- ;;
esac
#Define song info variables
playerStatus=$(playerctl $ARGUMENTS status);
songArtist="$(playerctl $ARGUMENTS metadata artist)";
songArtist="${songArtist:-(Unknown Artist)}";
songTitle=$(playerctl $ARGUMENTS metadata title);
songInfo="$songArtist - $songTitle";
songDuration="";
elapsedTime=$(playerctl metadata --format "{{ duration(position) }}");
songLength=$(playerctl metadata --format "{{ duration(mpris:length) }}");
#`playerctl position` doesn't work for "Spotify"
if [[ $(playerctl -l) != "spotify" ]]; then
songDuration=" ($elapsedTime/$songLength)";
fi
#Display output
if [[ "${playerStatus^}" = "Paused" ]]; then
echo "$songInfo$songDuration$pauseIcon";
elif [[ "${playerStatus^}" = "Playing" ]]; then
echo "$songInfo$songDuration$playIcon";
elif [[ "${playerStatus^}" = "Stopped" ]]; then
echo "Stopped$stopIcon";
fi