-
Notifications
You must be signed in to change notification settings - Fork 0
/
playerCtrl.sh
executable file
·38 lines (34 loc) · 994 Bytes
/
playerCtrl.sh
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
#!/bin/bash
function listPlayers {
dbus-send --session --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus \
org.freedesktop.DBus.ListNames | grep org.mpris.MediaPlayer2 | awk -F\" '{print $2}' | cut -d '.' -f4-
}
function getPlayerStatus {
playerctl --player="$1" status
}
function getActivePlayer {
players=("$(listPlayers)")
for player in "${players[@]}"; do
if [ "$(getPlayerStatus "${player}")" == "Playing" ]; then
playing=$player
fi
done
for player in "${players[@]}"; do
if [ "$(getPlayerStatus "${player}")" == "Paused" ]; then
paused=$player
fi
done
if [ -n "$playing" ]; then
echo "$playing"
elif [ -n "$paused" ]; then
echo "$paused"
else
# Return last (newest?) player
echo "${players[@]: -1}"
fi
}
if [ "$1" == "--get-active" ]; then
getActivePlayer
else
exec playerctl --player="$(getActivePlayer)" "$@"
fi