forked from aario/dmenu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dmenu_media
executable file
·59 lines (51 loc) · 1.63 KB
/
dmenu_media
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
#!/bin/bash
#based on Exic player-control gist:
# https://gist.github.com/exic/1d051e3a15f61e06caf4
#
#Needs DBUS and a media player (VLC) to work
name=`dbus-send --session --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames | grep mpris | cut -d '"' -f 2`
PATHS="$name /org/mpris/MediaPlayer2"
DBUS_SEND="dbus-send --type=method_call --dest=$PATHS"
RC="$DBUS_SEND org.mpris.MediaPlayer2.Player"
if [ $# -eq 1 ]; then
if [ $1 == '--playpause' ]; then
$RC.PlayPause
exit 0
fi
if [ $1 == '--stop' ]; then
$RC.Stop
set_volume $vol
exit 0
fi
if [ $1 == '--previous' ]; then
$RC.Previous
exit 0
fi
if [ $1 == '--next' ]; then
$RC.Next
exit 0
fi
fi
media_menu() {
name=`dbus-send --session --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames | grep mpris | cut -d '"' -f 2`
title=`dbus-send --print-reply --session --dest=$name /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata' | grep -A 1 title | grep variant | cut -d '"' -f2`
if [ ${#title} -gt 50 ]; then
title=`echo "$title" | cut -c 1-47`
title="$title..."
fi
{ echo " |<< "; echo " [>|| "; echo " [] "; echo " >>| "; } | dmenu -p "$title" -s -d 1 -l 0 $menu_params
}
export -f media_menu
export menu_params="$@"
stdbuf -oL bash -c 'media_menu' | while read -r command; do
if [ "$command" = "|<<" ]; then
$RC.Previous
elif [ "$command" = "[>||" ]; then
$RC.PlayPause
elif [ "$command" = ">>|" ]; then
$RC.Next
elif [ "$command" = "[]" ]; then
$RC.Stop
fi
done
exit 1