-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspotify-panel.sh
executable file
·36 lines (29 loc) · 1.23 KB
/
spotify-panel.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
#!/usr/bin/env bash
readonly DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# settings
readonly ICON="${DIR}/icons/spotify.png"
readonly ICON_OFFLINE="${DIR}/icons/spotify_offline.png"
readonly DISPALY_TITLE_MAX_LENGTH=20
encode () {
echo $@ | sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/g'
}
if pidof spotify &> /dev/null; then
# Use the command-line Spotify controller to get song info over dbus
eval $(${DIR}/sp.sh eval)
# grab window id
WINDOW_ID=$(wmctrl -l | grep "${SPOTIFY_ARTIST} - ${SPOTIFY_TITLE}\|Spotify" | awk '{print $1}')
# trim title of song
DISPLAY_TITLE=$SPOTIFY_TITLE
[ "${#DISPLAY_TITLE}" -gt "${DISPALY_TITLE_MAX_LENGTH}" ] && \
DISPLAY_TITLE="${SPOTIFY_TITLE:0:DISPALY_TITLE_MAX_LENGTH} …"
echo "<img>${ICON}</img>"
echo "<txt>$(encode ${SPOTIFY_ARTIST}) - $(encode ${DISPLAY_TITLE})</txt>"
echo "<click>xdotool windowactivate ${WINDOW_ID}</click>"
echo "<tool>Title $(encode ${SPOTIFY_TITLE})"
echo "Artist $(encode ${SPOTIFY_ARTIST})"
echo "Album $(encode ${SPOTIFY_ALBUM})</tool>"
else
echo "<img>${ICON_OFFLINE}</img>"
echo "<tool>Spotify is not running</tool>"
echo "<click>spotify</click>"
fi