-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspotifyChangeSong.sh
executable file
·85 lines (76 loc) · 1.42 KB
/
spotifyChangeSong.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
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
# Collect DBUS_SESSION_BUS_ADDRESS from running process
function set_dbus_adress
{
USER=$1
PROCESS=$2
PID=`pgrep -o -u $USER $PROCESS`
ENVIRON=/proc/$PID/environ
if [ -e $ENVIRON ]
then
export `grep -z DBUS_SESSION_BUS_ADDRESS $ENVIRON`
else
echo "Unable to set DBUS_SESSION_BUS_ADDRESS."
exit 1
fi
}
function spotify_cmd
{
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.$1 1> /dev/null
}
function spotify_query
{
qdbus org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get org.mpris.MediaPlayer2.Player PlaybackStatus
}
function quit_message
{
echo "Usage: `basename $0` {play|pause|playpause|next|previous|stop|playstatu s|<spotify URI>}"
exit 1
}
# Count arguments, must be 1
if [ "$#" -ne "1" ]
then
echo -e "You must supply exactly one argument!\n"
quit_message
fi
# Check if DBUS_SESSION is set
if [ -z $DBUS_SESSION_BUS_ADDRESS ]
then
#echo "DBUS_SESSION_BUS_ADDRESS not set. Guessing."
set_dbus_adress `whoami` spotify
fi
case "$1" in
play)
spotify_cmd Play
;;
pause)
spotify_cmd Pause
;;
playpause)
spotify_cmd PlayPause
;;
next)
spotify_cmd Next
;;
previous)
spotify_cmd Previous
;;
stop)
spotify_cmd Stop
;;
spotify:user:*)
spotify_cmd "OpenUri string:$1"
spotify_cmd Play
;;
spotify:*:*)
spotify_cmd "OpenUri string:$1"
;;
playstatus)
spotify_query
;;
*)
echo -e "Bad argument.\n"
quit_message
;;
esac
exit 0