-
Notifications
You must be signed in to change notification settings - Fork 0
/
music-controls-like.10s.sh
executable file
·91 lines (78 loc) · 5.24 KB
/
music-controls-like.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
#!/bin/bash
# Like the current track in iTunes 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 - Like 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>Likes the current track in iTunes 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"
like_icon_light="iVBORw0KGgoAAAANSUhEUgAAACQAAAAkCAYAAADhAJiYAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAWJQAAFiUBSVIk8AAAAVlpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IlhNUCBDb3JlIDUuNC4wIj4KICAgPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJ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like track in music application
if [[ "$1" = 'itunes_like' ]]; then
osascript -e 'tell application "iTunes"' -e 'if loved of current track is true then' -e 'set loved of current track to false' -e 'else' -e 'set loved of current track to true' -e 'end if' -e 'end tell'
exit
fi
if [[ "$1" = 'pianobar_like' ]]; then
echo -ne "\n+" > "$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
# cmus does not support likes
exit
elif [[ $s = "$ITUNES" && $itunes_pid ]]; then
current_source="$ITUNES"
break
elif [[ $s = "$SPOTIFY" && $spotify_pid ]]; then
# spotify (applescript) api does not support likes
exit
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 like track icon based on dark mode setup
if [[ "$BitBarDarkMode" ]]; then
icon=$like_icon_dark
else
icon=$like_icon_light
fi
# Trigger like track in correct music app
if [[ $current_source = "$ITUNES" ]]; then
echo " | image=$icon bash='$0' param1='itunes_like' terminal=false refresh=false"
elif [[ $current_source = "$PIANOBAR" ]]; then
echo " | image=$icon bash='$0' param1='pianobar_like' terminal=false refresh=false"
fi