-
Notifications
You must be signed in to change notification settings - Fork 0
/
music-controls-next.10s.sh
executable file
·103 lines (90 loc) · 5.29 KB
/
music-controls-next.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
# Plays the next track in cmus, iTunes, Spotify or pianobar.
#
# Special thanks to Google for providing the open-source icons: https://github.com/google/material-design-icons
# and to mcchrish and alekseysotnikov for their helpful existing BitBar scripts
#
# metadata
# <bitbar.title>Music Controls - Next Track Button</bitbar.title>
# <bitbar.version>v1.0</bitbar.version>
# <bitbar.author>Sebastián Barschkis</bitbar.author>
# <bitbar.author.github>sebbas</bitbar.author.github>
# <bitbar.desc>Plays the next track in cmus, iTunes, Spotify or pianobar.</bitbar.desc>
# <bitbar.image>https://raw.githubusercontent.com/sebbas/music-controls-bitbar/master/music-controls-screenshot.png</bitbar.image>
# <bitbar.abouturl>http://github.com/sebbas/music-controls-bitbar</bitbar.abouturl>
export PATH="/usr/local/bin:/usr/bin:/bin:$PATH"
export LC_CTYPE="UTF-8"
pianobar_ctlfile="$HOME/.config/pianobar/ctl"
NONE="none"
CMUS="cmus"
ITUNES="iTunes"
SPOTIFY="Spotify"
PIANOBAR="pianobar"
next_icon_light="iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAWJQAAFiUBSVIk8AAAAVlpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IlhNUCBDb3JlIDUuNC4wIj4KICAgPHJkZjpSREYgeG1sbnM6cm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uNC4wIj4KICAgPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICAgICAgPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIKICAgICAgICAgICAgeG1sbnM6dGlmZj0iaHR0cDovL25zLmFkb2JlLmNvbS90aWZmLzEuMC8iPgogICAgICAgICA8dGlmZjpPcmllbnRhdGlvbj4xPC90aWZmOk9yaWVudGF0aW9uPgogICAgICA8L3JkZjpEZXNjcmlwdGlvbj4KICAgPC9yZGY6UkRGPgo8L3g6eG1wbWV0YT4KTMInWQAAAYVJREFUaAXtWDFOAzEQPCGCUtEgpaGmpEjLC6j5BT+AH+QFvIGGmhfQUlBSUyGaNCmQ0DEX2ZIzOnnXXoNkaSNZ9mZnduzZXHKXYfCXO+AOuAPugDvgDrgD7oDagXEcHzFO1QQBiFoHLwFuTwe1D8xX9mrDcLB7BC1qZmskgj9YbzCOswQhmdTbLwW4Pc2CiF8xLmorc73aOmoeC4Z4h/lWXSQBcr0k9TdLFqT4GfFZiTLx//UaYO0Yf2JxrT1EJMVZy6vGRSHF/ADMUhLiOhLenGdBIX5H/jInyvwctkmOBRXxNzB3GEdzG2D+HKbpeyxYEL8Ae86bYT7nm8csWBhvgb9JN8X8NKdZz7ZVQzRgTgxcO5UdK4i7/QhNF/E9xmy32QC7xUIFFhTi6Wt0nSvJ/By2SY4FM3G3P2RfOFS3txLTzdyqpNXcwRJuFZYFQ9z17fQbDtHlA018pFxUtTKQuKOWWipuEOz6of4Jh+j3bxVVmxzkDrgD7oA74A64A+5AHw78AkOdplKAcgGEAAAAAElFTkSuQmCC"
# Trigger next track in music application
if [[ "$1" = 'cmus_next' ]]; then
cmus-remote --next
exit
fi
if [[ "$1" = 'itunes_next' ]]; then
osascript -e 'tell application "iTunes" to next track'
exit
fi
if [[ "$1" = 'spotify_next' ]]; then
osascript -e 'tell application "Spotify" to next track'
exit
fi
if [[ "$1" = 'pianobar_next' ]]; then
echo -ne "\nn" > "$pianobar_ctlfile"
exit
fi
# Ensure that pianobar fifo config file exists
if [ ! -e "$pianobar_ctlfile" ]; then
mkfifo "$pianobar_ctlfile"
fi
BitBarDarkMode=${BitBarDarkMode}
current_source="$NONE"
# Get pid of music apps to see if they are currently running
cmus_pid=$(pgrep -x "$CMUS")
itunes_pid=$(pgrep -x "$ITUNES")
spotify_pid=$(pgrep -x "$SPOTIFY")
pianobar_pid=$(pgrep -x "$PIANOBAR")
# Keep track of music source
# Reorder items in for-loop to your liking to change order of precendece
# (i.e. if available, left-most audio source will be used first)
for s in "$CMUS" "$ITUNES" "$SPOTIFY" "$PIANOBAR"; do
if [[ $s = "$CMUS" && $cmus_pid ]]; then
current_source="$CMUS"
break
elif [[ $s = "$ITUNES" && $itunes_pid ]]; then
current_source="$ITUNES"
break
elif [[ $s = "$SPOTIFY" && $spotify_pid ]]; then
current_source="$SPOTIFY"
break
elif [[ $s = "$PIANOBAR" && $pianobar_pid ]]; then
current_source="$PIANOBAR"
break
fi
done
# Do not display menu icon if no audio source is active
if [[ $current_source = "$NONE" ]]; then
exit
fi
# Set next track icon based on dark mode setup
if [[ "$BitBarDarkMode" ]]; then
icon=$next_icon_dark
else
icon=$next_icon_light
fi
# Trigger next track in correct music app
if [[ $current_source = "$CMUS" ]]; then
echo " | image=$icon bash='$0' param1='cmus_next' terminal=false refresh=false"
elif [[ $current_source = "$ITUNES" ]]; then
echo " | image=$icon bash='$0' param1='itunes_next' terminal=false refresh=false"
elif [[ $current_source = "$SPOTIFY" ]]; then
echo " | image=$icon bash='$0' param1='spotify_next' terminal=false refresh=false"
elif [[ $current_source = "$PIANOBAR" ]]; then
echo " | image=$icon bash='$0' param1='pianobar_next' terminal=false refresh=false"
fi