forked from matryer/xbar-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspotify.10s.sh
executable file
·87 lines (73 loc) · 2.4 KB
/
spotify.10s.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
86
87
#!/bin/bash
# Get current Spotify status with play/pause button
#
# by Jason Tokoph ([email protected])
#
# Shows current track information from spotify
# 10 second refresh might be a little too quick. Tweak to your liking.
# metadata
# <bitbar.title>Spotify Now Playing</bitbar.title>
# <bitbar.version>v1.2</bitbar.version>
# <bitbar.author>Jason Tokoph</bitbar.author>
# <bitbar.author.github>jtokoph</bitbar.author.github>
# <bitbar.desc>Display currently playing Spotify song. Play/pause, skip forward, skip backward.</bitbar.desc>
# <bitbar.image>http://i.imgur.com/y1SZwfq.png</bitbar.image>
function tellspotify() {
osascript -e "tell application \"Spotify\" to $1"
}
if [ "$1" = 'launch' ]; then
tellspotify 'activate'
exit
fi
if [ "$(osascript -e 'application "Spotify" is running')" = "false" ]; then
echo "♫"
echo "---"
echo "Spotify is not running"
echo "Launch Spotify | bash='$0' param1=launch terminal=false"
exit
fi
case "$1" in
'playpause' | 'previous track' | 'next track')
tellspotify "$1"
exit
esac
state=$(tellspotify 'player state as string');
track=$(tellspotify 'name of current track as string');
artist=$(tellspotify 'artist of current track as string');
if [ "$1" = 'lyrics' ]; then
osascript -e "do shell script \"open 'https://www.musixmatch.com/search/$track $artist'\""
exit
fi
if [ "$state" = "playing" ]; then
state_icon="▶"
else
state_icon="❚❚"
fi
suffix="..."
trunc_length=20
truncated_track=$track
if [ ${#track} -gt $trunc_length ];then
truncated_track=${track:0:$trunc_length-${#suffic}}$suffix
fi
truncated_artist=$artist
if [ ${#artist} -gt $trunc_length ];then
truncated_artist=${artist:0:$trunc_length-${#suffic}}$suffix
fi
album=$(tellspotify 'album of current track as string');
echo "$state_icon $truncated_track - $truncated_artist"
echo "---"
echo "Track: $track | color=#333333"
echo "Artist: $artist | color=#333333"
echo "Album: $album | color=#333333"
echo '---'
echo "🎵 Lyrics | bash='$0' param1='lyrics' terminal=false"
echo '---'
if [ "$state" = "playing" ]; then
echo "⏸ Pause | bash='$0' param1=playpause terminal=false"
echo "⏮ Previous | bash='$0' param1='previous track' terminal=false refresh=true"
echo "⏭ Next | bash='$0' param1='next track' terminal=false refresh=true"
else
echo "▶️ Play | bash='$0' param1=playpause terminal=false"
fi
echo '---'
echo "Open Spotify | bash='$0' param1=launch terminal=false"