-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathitunes.10s.sh
executable file
·207 lines (183 loc) · 5.43 KB
/
itunes.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/bin/bash
# Get current iTunes status with play/pause button
#
# based on Spotify script by Jason Tokoph (jason@tokoph.net),
# tweaked by Dan Turkel (daturkel@gmail.com),
# additionally tweaked by Aleš Farčnik (@alesf)
#
# Shows current track information from iTunes
# 10 second refresh might be a little too quick. Tweak to your liking.
# metadata
# <bitbar.title>iTunes Now Playing</bitbar.title>
# <bitbar.version>v1.1</bitbar.version>
# <bitbar.author>Dan Turkel, Jason Tokoph, Aleš Farčnik</bitbar.author>
# <bitbar.author.github>daturkel</bitbar.author.github>
# <bitbar.desc>Display currently playing iTunes song with artwork. Play/pause, skip forward, skip backward.</bitbar.desc>
# <bitbar.image>http://i.imgur.com/lBfoFdY.png</bitbar.image>
if [ "$1" = 'launch' ]; then
osascript -e 'tell application "iTunes" to activate'
exit
fi
if [ "$1" = 'open' ]; then
osascript -e 'tell application "iTunes" to reopen'
osascript -e 'tell application "iTunes" to activate'
exit
fi
if [ "$(osascript -e 'application "iTunes" is running')" = "false" ]; then
echo "♫ | size=12"
echo "---"
echo "iTunes is not running"
echo "Launch iTunes | bash='$0' param1=launch terminal=false"
exit
fi
if [ "$1" = 'playpause' ]; then
osascript -e 'tell application "iTunes" to playpause'
exit
fi
if [ "$1" = 'previous' ]; then
osascript -e 'tell application "iTunes" to previous track'
exit
fi
if [ "$1" = 'next' ]; then
osascript -e 'tell application "iTunes" to next track';
exit
fi
BitBarDarkMode=${BitBarDarkMode}
if [ "$BitBarDarkMode" ]; then
COLOR0="#666666"
COLOR1="#ffffff"
COLOR2="#666666"
COLOR3="#333333"
else
COLOR0="#333333"
COLOR1="#000000"
COLOR2="#666666"
COLOR3="#999999"
fi
state=$(osascript -e '
try
tell application "iTunes"
with timeout 3 seconds
player state as string
end timeout
end tell
on error errText
"not available"
end try
');
if [ "$state" = "not available" ]; then
echo "♫ | size=12"
echo "---"
echo "iTunes is not available"
exit
fi
track=$(osascript -e'
try
tell application "iTunes" to name of current track as string
on error errText
"no track selected"
end try
');
artist=$(osascript -e'
try
tell application "iTunes" to artist of current track as string
on error errText
""
end try
');
album=$(osascript -e'
try
tell application "iTunes" to album of current track as string
on error errText
""
end try
');
tmp_file=$(osascript -e'
try
tell application "iTunes"
tell artwork 1 of current track
if format is JPEG picture then
set imgFormat to ".jpg"
else
set imgFormat to ".png"
end if
end tell
set albumName to album of current track
set albumArtist to album artist of current track
if length of albumArtist is 0
set albumArtist to artist of current track
end if
set fileName to (do shell script "echo " & quoted form of albumArtist & quoted form of albumName & " | sed \"s/[^a-zA-Z0-9]//g\"") & imgFormat
end tell
(POSIX path of (path to temporary items from user domain)) & fileName
on error errText
""
end try
');
if [ ! -f "$tmp_file" ]; then
osascript -e'
try
tell application "iTunes"
tell artwork 1 of current track
set srcBytes to raw data
if format is JPEG picture then
set imgFormat to ".jpg"
else
set imgFormat to ".png"
end if
end tell
set albumName to album of current track
set albumArtist to album artist of current track
if length of albumArtist is 0
set albumArtist to artist of current track
end if
set fileName to (do shell script "echo " & quoted form of albumArtist & quoted form of albumName & " | sed \"s/[^a-zA-Z0-9]//g\"") & imgFormat
end tell
set tmpName to ((path to temporary items from user domain) as text) & fileName
set outFile to open for access file tmpName with write permission
set eof outFile to 0
write srcBytes to outFile
close access outFile
tell application "Image Events"
set resImg to open tmpName
scale resImg to size 200
save resImg
close resImg
end tell
tmpName
on error errText
""
end try
'
fi
if [ -f "$tmp_file" ]; then
base64img=$(base64 < "$tmp_file")
fi
if [ "$state" = "playing" ]; then
state_icon="▶︎"
else
state_icon="𝝞𝝞"
fi
if [ "$track" != "no track selected" ]; then
echo "♫ $state_icon $track - $artist | color=$COLOR0 size=12"
else
echo "♫ ◼︎ | color=$COLOR0 size=12"
fi
echo "---"
if [ "$state" = "playing" ]; then
echo "𝝞𝝞 Pause | bash='$0 'param1=playpause terminal=false refresh=true color=$COLOR0"
echo "« Previous | bash='$0' param1=previous terminal=false refresh=true color=$COLOR0"
echo "» Next | bash='$0' param1=next terminal=false refresh=true color=$COLOR0"
else
echo "▶︎ Play | bash='$0' param1=playpause terminal=false refresh=true color=$COLOR0"
fi
echo "---"
if [ "$track" != "no track selected" ] && [ "$base64img" != "" ]; then
echo "| image=$base64img bash='$0' param1=open terminal=false"
fi
if [ "$track" != "no track selected" ]; then
echo "$track | color=$COLOR1"
echo "$artist | color=$COLOR2"
echo "$album | size=12 color=$COLOR3 length=30"
fi
echo '---'