-
Notifications
You must be signed in to change notification settings - Fork 20
/
pctl
executable file
·70 lines (59 loc) · 1.32 KB
/
pctl
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env bash
# playerctl, but fast
# skip the fetching of metadata overhead of playerctl
# author: Ayose C (ayosec)
# adapted and modified by: Sayan Ghosh (sayan01)
#
usage(){
echo "Usage: $0 [player] n|next|p|prev|previous|play|pause|pp|play-pause|s|stop|stat|status|v|vol|volume" >&2
exit 1
}
if [[ "$#" -eq 0 ]]; then
usage
fi
if [[ "$#" -gt 1 ]]; then
player="$1"
else
player="$(playerctl -l | head -n 1)"
fi
command="${*: -1}"
case "${command:-}" in
n) ;& # fallthrough
next)
MEMBER=Next
;;
p) ;& # fallthrough
prev) ;& # fallthrough
previous)
MEMBER=Previous
;;
play)
MEMBER=Play
;;
pause)
MEMBER=Pause
;;
pp) ;& # fallthrough
play-pause)
MEMBER=PlayPause
;;
s) ;& # fallthrough
stop)
MEMBER=Stop
;;
stat) ;& # fallthrough
status)
PROPERTY=PlaybackStatus ;;
v) ;& # fallthrough
vol) ;& # fallthrough
volume)
PROPERTY=Volume ;;
*)
usage
;;
esac
if [[ -n "$PROPERTY" ]] ; then
dbus-send --print-reply --dest="org.mpris.MediaPlayer2.$player" /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:"org.mpris.MediaPlayer2.Player" string:"$PROPERTY" | awk 'END{ print $NF }'
else
dbus-send --print-reply --dest="org.mpris.MediaPlayer2.$player" /org/mpris/MediaPlayer2 "org.mpris.MediaPlayer2.Player.$MEMBER"
fi